By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,727 Members | 766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,727 IT Pros & Developers. It's quick & easy.

Select Listbox Item based on Textbox input

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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(textboxVal ue))
End Sub
this is obviously a simple example.

Karl

"RockNRoll" <da*******@yahoo.com> wrote in message
news:Od*************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2

P: n/a
Karl,

Thank you for your response. I apprecaite it.

-Dave
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:eW**************@TK2MSFTNGP09.phx.gbl...
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(textboxVal ue))
End Sub
this is obviously a simple example.

Karl

"RockNRoll" <da*******@yahoo.com> wrote in message
news:Od*************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #3

P: n/a
This should be better...

ListBox1.Items.FindByText("Seattle").Selected = True

From http://www.developmentnow.com/g/8_20...tbox-input.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.