473,799 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3488
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:dropdownli st id="ddl" runat="Server">
<asp:ListItem Value="1">Canad a</asp:ListItem>
<asp:ListItem Value="2">Unite d States</asp:ListItem>
<asp:ListItem Value="3">Mexic o</asp:ListItem>
</asp:dropdownlis t>
And your codebehind could look something like:

Protected WithEvents btn As System.Web.UI.W ebControls.Butt on
Protected txt As System.Web.UI.W ebControls.Text Box
Protected ddl As System.Web.UI.W ebControls.Drop DownList

Private Sub btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btn.Click
Dim textboxValue As String = txt.Text
ddl.SelectedInd ex =
ddl.Items.Index Of(ddl.Items.Fi ndByValue(textb oxValue))
End Sub
this is obviously a simple example.

Karl

"RockNRoll" <da*******@yaho o.com> wrote in message
news:Od******** *****@TK2MSFTNG P12.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******** ******@TK2MSFTN GP09.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:dropdownli st id="ddl" runat="Server">
<asp:ListItem Value="1">Canad a</asp:ListItem>
<asp:ListItem Value="2">Unite d States</asp:ListItem>
<asp:ListItem Value="3">Mexic o</asp:ListItem>
</asp:dropdownlis t>
And your codebehind could look something like:

Protected WithEvents btn As System.Web.UI.W ebControls.Butt on
Protected txt As System.Web.UI.W ebControls.Text Box
Protected ddl As System.Web.UI.W ebControls.Drop DownList

Private Sub btn_Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btn.Click
Dim textboxValue As String = txt.Text
ddl.SelectedInd ex =
ddl.Items.Index Of(ddl.Items.Fi ndByValue(textb oxValue))
End Sub
this is obviously a simple example.

Karl

"RockNRoll" <da*******@yaho o.com> wrote in message
news:Od******** *****@TK2MSFTNG P12.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("Sea ttle").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
2653
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, these combo boxes will have a *large* number of values. There could be any number of values in them from 5 to 5 million (unlikely it would be this large but possible). Obviously 5 million is far too much to populate a <select> control with. Does...
19
3574
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 form, the subform returns the records based on the two criteria. The criteria used on the main form are values selected in two list boxes. When the user clicks on the first list box (lstCollege), it returns values in the second list box...
2
23361
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 show up for each item I add to the listbox. foreach (Column column in columns) { ColumnsListBox.Items.Add(column.Name); ColumnsListBox.Controls.Add(new ColumnListControl(true, column.Name,
7
4227
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 the first item in the dropdown is always displayed. Template Code: <asp:TemplateColumn HeaderText="DropDown"> <ItemTemplate> <asp:Label runat="server" Text='<%# DataBinder.Eval
4
5105
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 address book on the left, and you build the message recipients on the right. * an asp:button that, when clicked, fires off some code to create and send the mail message
8
2432
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 PersonData Table that I have filled out and look at each MemberAlias column for each Person on the Table. It will then retrieve any persons with that MemberAlias and populate it into a ListBox, where they can then select the record from that list box...
1
5638
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, other program), the list of names appear. How can I select the name in the listbox with the keyboard if i want to select the eighth name in the list. How can I make the listbox appear when I enter the first 2 characters in the
9
3250
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). This listbox has AutoPostback = True. When the user selects an item from this list, the second listbox is populated with more items relevant to this selection. I am using an SQLDataSource web control for this. These items are headers. I want, when...
1
4033
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 are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10488
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.