[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

How to find value or text in DropDownList

I have a DropDownList with the text  displayed as

Z11-Elements of Chemistry
A97-Biology...
etc...

I d like to search only for 'Z11' or 'A97'-  
or the first 3 strings...
0
zachvaldez
Asked:
zachvaldez
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
0
 
ddayx10Commented:
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.

0
 
CodeCruiserCommented:
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

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

2)
ID = Value.Substring(0, 3)

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
            xdoc.Load(Server.MapPath("workshopA.xml"))



            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)

                items.Add(item)

            Next

            Me.DropDownList9.DataSource = items
            Me.DropDownList9.DataBind()

Any idea?
0
 
CodeCruiserCommented:
> 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?
0
 
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.
0
 
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
            Next
0
 
zachvaldezAuthor Commented:
Im posting the solution to this question.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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