472,126 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

Select Listbox Item based on Textbox input

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
3 3355
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
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
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.

Similar topics

2 posts views Thread by John R. | last post: by
7 posts views Thread by localhost | last post: by
8 posts views Thread by daddydfsu via AccessMonster.com | last post: by
9 posts views Thread by zdrakec | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.