473,669 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listbox Selected Text

I'm using ASP.Net and 1 Listbox and 1 ComboBox.
When a user selects the contents in the listbox I want to populate the
combobox with the text that he selected or double clicked. I've tried
various things with the selecteditem, index properties to no avail.

Meaning: LISTBOX has CAR, DOG, BAT, HAT already populated in it.
When user selects DOG -> I would like to populate the ComboBox with DOG.

I'm writing everything in the vb file in code.

Thanks.
Nov 18 '05 #1
2 1614
Hi E?

Don't forget to set AutoPostBack="T rue" for the listbox. That will fire the
event in which you can transfer the item. Here's some code in VB:

Private Sub ListBox1_Select edIndexChanged _
(ByVal sender As Object, _
ByVal e As System.EventArg s) _
Handles ListBox1.Select edIndexChanged
Dim li As ListItem
li = ListBox1.Select edItem
DropDownList1.I tems.Add(li)
DropDownList1.S electedIndex = -1
ListBox1.Items. Remove(li)
End Sub

<form id="Form1" method="post" runat="server">
<asp:ListBox id="ListBox1" runat="server" AutoPostBack="T rue">
<asp:ListItem Value="CAR">CAR </asp:ListItem>
<asp:ListItem Value="DOG">DOG </asp:ListItem>
<asp:ListItem Value="BAT">BAT </asp:ListItem>
<asp:ListItem Value="HAT">HAT </asp:ListItem>
</asp:ListBox>
<asp:DropDownLi st id="DropDownLis t1" runat="server"> </asp:DropDownLis t>
</form>

Does this help?

Ken
Microsoft MVP [ASP.NET]
"Big E" <no****@nospam. com> wrote in message
news:O9******** ******@tk2msftn gp13.phx.gbl...
I'm using ASP.Net and 1 Listbox and 1 ComboBox.
When a user selects the contents in the listbox I want to populate the
combobox with the text that he selected or double clicked. I've tried
various things with the selecteditem, index properties to no avail.

Meaning: LISTBOX has CAR, DOG, BAT, HAT already populated in it.
When user selects DOG -> I would like to populate the ComboBox with DOG.

I'm writing everything in the vb file in code.

Thanks.


Nov 18 '05 #2
Perfecto.

"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi E?

Don't forget to set AutoPostBack="T rue" for the listbox. That will fire the event in which you can transfer the item. Here's some code in VB:

Private Sub ListBox1_Select edIndexChanged _
(ByVal sender As Object, _
ByVal e As System.EventArg s) _
Handles ListBox1.Select edIndexChanged
Dim li As ListItem
li = ListBox1.Select edItem
DropDownList1.I tems.Add(li)
DropDownList1.S electedIndex = -1
ListBox1.Items. Remove(li)
End Sub

<form id="Form1" method="post" runat="server">
<asp:ListBox id="ListBox1" runat="server" AutoPostBack="T rue">
<asp:ListItem Value="CAR">CAR </asp:ListItem>
<asp:ListItem Value="DOG">DOG </asp:ListItem>
<asp:ListItem Value="BAT">BAT </asp:ListItem>
<asp:ListItem Value="HAT">HAT </asp:ListItem>
</asp:ListBox>
<asp:DropDownLi st id="DropDownLis t1" runat="server"> </asp:DropDownLis t>
</form>

Does this help?

Ken
Microsoft MVP [ASP.NET]
"Big E" <no****@nospam. com> wrote in message
news:O9******** ******@tk2msftn gp13.phx.gbl...
I'm using ASP.Net and 1 Listbox and 1 ComboBox.
When a user selects the contents in the listbox I want to populate the
combobox with the text that he selected or double clicked. I've tried
various things with the selecteditem, index properties to no avail.

Meaning: LISTBOX has CAR, DOG, BAT, HAT already populated in it.
When user selects DOG -> I would like to populate the ComboBox with DOG.

I'm writing everything in the vb file in code.

Thanks.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
6997
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have it return the associated records to a listbox. Once the listbox has the records, I want to select a record, which will open a form associated with the selected record in the listbox.
1
8383
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's Address1, Address2 etc. controls with the relevant data items. I put the code for this into the...
6
2872
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
4
2449
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item, what do I need to do in order to return the "option value" of the control? Moe !--- returned value of the control
6
5206
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I have also tried changing the second ListBox to an HtmlSelect control) using bog standard JavaScript code like so where "used" is the name of my <select> control: used.options = new Option(name, typeId); This all works fine and I can move across...
1
2882
by: JMann101 | last post by:
I am writing a ASP.NET(VB) application and am having some trouble. I have a datagrid which list users and when an admin clicks "edit" a defined column becomes visible and a dynamic listbox control is added to that column/row. When the admin clicks "update" I am unable to retrieve the values that were selected from that listbox. Basically, This is a multi-select listbox, so I need to loop to pull all selected items. This is the only...
5
2290
by: Doug Bell | last post by:
Hi, I thought that this would be a simple exercise but I am struggling to get a result. I need a listbox that will display a list of items from a DataTable, dtUnits. The displayed list comes from Column . Selecting an item in this list needs to return a value from Column . Data in dtUnits is UnitsProdDescn UnitsConvn Carton 3.2
2
6313
by: php_Boi | last post by:
i have designed an application that is a dynamic submission form. i have text fields and listboxes. now i am able to retain the values of the listboxes when i populate the listbox "manually"(single listbox) like this... <select name="title"> <option value="1"<?php if ($_POST == '1') { echo 'selected="selected"'; } ?>></option> <option value="Mr"<?php if ($_POST == 'Mr') { echo 'selected="selected"'; } ?>>Mr</option>
9
3215
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...
9
2185
by: Bob Malcoprs | last post by:
Hi, I want to get all the selected values of a listbox in several labels.. With this code here below, when i click on e.g. "option 2", i get '2' in label2. That's ok. But if i then click on "option 3", "option 3" is selected and "option 2" is deselected. So i get '3' in label3 but also still '2' in label2. Same with "option 1". And when i deselect everything, i still get '2' and '3'. I can't get rid of them.
0
8465
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
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8894
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
8803
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
8587
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
8658
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.