• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

How to find value or text in DropDownList

I have a DropDownList with the text  displayed as

Z11-Elements of Chemistry

I d like to search only for 'Z11' or 'A97'-  
or the first 3 strings...
2 Solutions
Umar Topia.Net Full Stack DeveloperCommented:
You will have to use a plugin provided by JQuery (something named as AutoFill)

or else write your own code to loop through the datasource and filter it based on the typed in characters
Seems simple enough but can you define the problem a little better. Search where? During what part of the process? When do you want to sort out these items? How is the dropdownlist filled if that's relavent. Show some code if it would be helpful.

For example:

After the user selects a choice in the dropdown then they do some other junk and press a submit button. At this point we want to find the 3 alpha-numerics that were selected as described.

If you want to get the first three letters after user makes a selection in the dropdown, you can use some string functions.

Dim Value As String = ddl.SelectedValue
Dim ID as String

ID = Value.Split("-")(0)

ID = Value.Substring(0, 3)

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

zachvaldezAuthor Commented:
here's the direction Im trying to accomplish...

 If e.CommandName = "Edit" Then

  Dim lblFChoice As Label = CType(e.Item.FindControl("lblfirstchoiceA"), Label)

'Here is where Im  having error trying to define and search for the text...
    DropDownList9.SelectedValue = lblFChoice.Text(this line is incorrect) I think I need to find the value of the label in the dropdownlist9. Im only searching for the fors 3 chars of the datatext pf the ddl.

BTW I load my dropdownlist9 with this code... and this work

   Dim xdoc As New System.Xml.XmlDocument()
        Dim items As New List(Of String)
        If Not IsPostBack Then

            For Each row As System.Xml.XmlNode In xdoc.SelectNodes("//row")
                Dim item As String = row.SelectSingleNode("Workshop").InnerText

                item = String.Concat(item, "-", row.SelectSingleNode("Title").InnerText)



            Me.DropDownList9.DataSource = items

Any idea?
> I think I need to find the value of the label in the dropdownlist9

You want the value from the dropdownlist then what does the label has to do with it?
zachvaldezAuthor Commented:
If the label has text of z11 for instance,it should find that text  in Ddl as z11-Elements.
And rebinds the ddl. I think I phrse question not that clear.
zachvaldezAuthor Commented:
here is the answer to my own question
          Dim lblFChoiceA As Label = CType(e.Item.FindControl("lblfirstchoiceA"), Label)
            Dim searchString As String = lblFChoiceA.Text.ToString()

            Dim iA As Integer
            For iA = 0 To Me.DropDownList9.Items.Count - 1
                If Left(Me.DropDownList9.Items(iA).Text, 3) = searchString Then
                    Me.DropDownList9.SelectedIndex = iA
                    Exit For
                End If
zachvaldezAuthor Commented:
Im posting the solution to this question.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now