473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 3440
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike | last post by:
My users have to select an value from a fixed selection of values. The obvious choice of control for such a requirement is to use a <select> (i.e. a combo box). My problem is that sometimes,...
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
2
by: John R. | last post by:
I want to have a listbox that shows a checkbox and a textbox. I created a user control that has a checkbox and a textbox in it and have been trying to add it to a listbox but I can't get it to...
7
by: localhost | last post by:
A DataGrid with shows a label in one of the columns when in view mode. When in edit mode, I want to show a dropdown, and have the default selection set to what the textbox used to be. Right now...
4
by: Bob P. | last post by:
Hello, I have a page with: * two side-by-side asp:listboxes and two arrow asp:buttons allowing users to add/remove email addresses between them -- very much like Outlook, where you have the...
8
by: daddydfsu via AccessMonster.com | last post by:
I am trying to create a ListBox based on a search from a TextBox. I have a TextBox where I will enter in a MemberAlias. I want to click on a Search Button and that will do a select from a...
1
by: Melson | last post by:
Hi Can anyone give suggestions please. I need to create a list (probably using listbox) and fill with names in the listbox. When I enter a name (maybe Adam) in a program (notepad, MS words,...
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.