Select Listbox Item based on Textbox input

R

RockNRoll

Greetings,

Can I select an item in a listbox based on user textbox entry and a submit
button? Can you provide any code examples for what needs to occur when the
user clicks submit? Thank you,

-Dave
 
K

Karl

Do you mean when a user enters something in a textbox and hits a button, you
want to have a value in a listbox selected? If so, then it's pretty easy.

<asp:textbox id="txt" runat="Server" /> <asp:button id="btn"
runat="server" Text="Go!" /><br /><br />
<asp:dropdownlist id="ddl" runat="Server">
<asp:ListItem Value="1">Canada</asp:ListItem>
<asp:ListItem Value="2">United States</asp:ListItem>
<asp:ListItem Value="3">Mexico</asp:ListItem>
</asp:dropdownlist>


And your codebehind could look something like:

Protected WithEvents btn As System.Web.UI.WebControls.Button
Protected txt As System.Web.UI.WebControls.TextBox
Protected ddl As System.Web.UI.WebControls.DropDownList

Private Sub btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn.Click
Dim textboxValue As String = txt.Text
ddl.SelectedIndex =
ddl.Items.IndexOf(ddl.Items.FindByValue(textboxValue))
End Sub


this is obviously a simple example.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top