By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,463 Members | 2,858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,463 IT Pros & Developers. It's quick & easy.

Listbox Selected Text

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.