DropDownList Selecting item

G

Guest

Using Visual Studio.net 2003 to create an aspx web form I am having a
problem selecting an item from DropDownListBox with id= ListBoxStudies.
I can see the items from the bound database table but when I click on an item
the selected item stays at itemindex 0. What must I do to have the
itemindex change when I click on an item. What's missing from the following
code?


ListBoxStudies.DataSource = BICDataSet.Tables("protocols")
ListBoxStudies.DataTextField = "Study_name"
ListBoxStudies.DataValueField = "irb_number"
ListBoxStudies.DataBind()


I have tested this using a submit button and the _SelectedIndexchanged event
and I still always get selectedindex = 0.

Private Sub DropDownListStudies_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Dim study_name As String = Session("study_name")
study_name = ListboxStudies.SelectedItem.Text
End Sub
 
S

Steve C. Orr [MVP, MCSD]

You may want to ensure you're binding only on the initial page load and not
on each postback, which could effectively overwrite the user's selection.
Here's an example:

'Page_Load event...
If Not Page.IsPostBack() Then
ListBoxStudies.DataSource = BICDataSet.Tables("protocols")
ListBoxStudies.DataTextField = "Study_name"
ListBoxStudies.DataValueField = "irb_number"
ListBoxStudies.DataBind()
End If
 
G

Guest

Wow! That was great; I gave you a direct question and you gave me a direct
and effective response. The application works: All is love; all is peace;
all is harmony.
--
Derek V. Taylor
UCI Brain Imaging Center


Steve C. Orr said:
You may want to ensure you're binding only on the initial page load and not
on each postback, which could effectively overwrite the user's selection.
Here's an example:

'Page_Load event...
If Not Page.IsPostBack() Then
ListBoxStudies.DataSource = BICDataSet.Tables("protocols")
ListBoxStudies.DataTextField = "Study_name"
ListBoxStudies.DataValueField = "irb_number"
ListBoxStudies.DataBind()
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top