How to iterate over a Single dropdownlist in asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davidson1
    New Member
    • Feb 2008
    • 144

    #1

    How to iterate over a Single dropdownlist in asp.net

    Hello to Everybody,

    I have a dropdownlist by name "Subject" which contain C,C++,Java,Php
    which is added by the following way

    subject.items.a dd("C")
    subject.items.a dd("C++")
    subject.items.a dd("Java")
    subject.items.a dd("Php")

    In the same webform

    i have a Textbox in that when user enter C or C++ or Java or Php

    i have to check this textbox text with Subject dropdownlist(No rmally Compare with every subject dropdownlist items)

    and Say this

    This Subject C or C++ or Java or Php have been entered in Subject dropdownlist... ..

    pl help me

    Posted Date:- 19 Feb 2008

    Davidson
  • int08h
    New Member
    • Apr 2007
    • 28

    #2
    if (subject.FindBy Text("C++") != null) {
    //then C++ exists in dropdownlits
    }

    Comment

    • davidson1
      New Member
      • Feb 2008
      • 144

      #3
      it shows an error

      Findbytext is not a member of dropdownlist

      if we should import any namespace , just tell me............ or if u know any other coding just tell me............. .............

      Davidson

      Posted Date:- 19 feb 2008

      Comment

      • int08h
        New Member
        • Apr 2007
        • 28

        #4
        sorry i've made a mistake
        the FindByText method belongs to ListItemCollect ion class, so the code should be

        subject.Items.F indByText("C++" )...

        Comment

        • kunal pawar
          Contributor
          • Oct 2007
          • 297

          #5
          try this

          DropDownList1.S electedIndex = DropDownList1.I tems.IndexOf(Dr opDownList1.Ite ms.FindByValue( <value>))
          'DropDownList1. SelectedIndex = DropDownList1.I tems.IndexOf(Dr opDownList1.Ite ms.FindByText(< Text>))

          Comment

          Working...