how to get index of a text in dropdownlist?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    how to get index of a text in dropdownlist?

    hai all, i am using asp.net(c#)
    in a dropdown list i am having the values like
    a
    b
    c
    d

    now i want to get the index of 'c'.
    how to get it?
    thanx in advance
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by nirmalsingh
    hai all, i am using asp.net(c#)
    in a dropdown list i am having the values like
    a
    b
    c
    d

    now i want to get the index of 'c'.
    how to get it?
    thanx in advance
    Dim index as Integer=dropdow nlist1.Selected Index....
    and if you know the Item name then
    dropdownlist1.I tems.IndexOf("I tem-Name")

    ...as simple as that....what problem..???

    Comment

    • balame2004
      New Member
      • Mar 2008
      • 142

      #3
      Originally posted by nirmalsingh
      hai all, i am using asp.net(c#)
      in a dropdown list i am having the values like
      a
      b
      c
      d

      now i want to get the index of 'c'.
      how to get it?
      thanx in advance

      Hi,

      Try this:
      dropdownList.It ems.IndexOf("c" );


      Cheers,
      Balaji U

      Comment

      • kunal pawar
        Contributor
        • Oct 2007
        • 297

        #4
        this will you

        create list item of same string u have to search and pass list item to IndexOf function
        like
        Dim lst = New ListItem("C")
        dropdown.Items. IndexOf(lst)

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          Just so you know, kunal pawar and dip_developer gave you the VB code.
          balame2004's is the C# code you need.

          Comment

          • nirmalsingh
            New Member
            • Sep 2006
            • 218

            #6
            thank you all, it is working.

            Comment

            Working...