473,320 Members | 1,948 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,320 software developers and data experts.

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 1599
Hi E?

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

Private Sub ListBox1_SelectedIndexChanged _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
Dim li As ListItem
li = ListBox1.SelectedItem
DropDownList1.Items.Add(li)
DropDownList1.SelectedIndex = -1
ListBox1.Items.Remove(li)
End Sub

<form id="Form1" method="post" runat="server">
<asp:ListBox id="ListBox1" runat="server" AutoPostBack="True">
<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:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
</form>

Does this help?

Ken
Microsoft MVP [ASP.NET]
"Big E" <no****@nospam.com> wrote in message
news:O9**************@tk2msftngp13.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****************@tk2msftngp13.phx.gbl...
Hi E?

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

Private Sub ListBox1_SelectedIndexChanged _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
Dim li As ListItem
li = ListBox1.SelectedItem
DropDownList1.Items.Add(li)
DropDownList1.SelectedIndex = -1
ListBox1.Items.Remove(li)
End Sub

<form id="Form1" method="post" runat="server">
<asp:ListBox id="ListBox1" runat="server" AutoPostBack="True">
<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:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
</form>

Does this help?

Ken
Microsoft MVP [ASP.NET]
"Big E" <no****@nospam.com> wrote in message
news:O9**************@tk2msftngp13.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
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...
1
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...
6
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...
4
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,...
6
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...
1
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...
5
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...
2
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...
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)....
9
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

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.