dropDownList always returns 0 for selected index

D

Dica

if i manually populate a dropDownList, post the page, and then fetch the
selected index, i'm able to get values other than 0. however, when i bound
my dropDownList to a dataReader object, even thought he dropDown's text and
values are showing the dataReader's data fine, i can never return a
selectedIndex other than 0.

lstCompanies.DataSource = oDataReader

lstCompanies.DataTextField = "companyName"

lstCompanies.DataValueField = "id"

lstCompanies.DataBind()



any ideas why?



tks
 
S

ScottStoecker

Where has this code been placed - in the Page_Load event? And is it
inside a IsPostBack check.

If Not Page.IsPostBack Then
'databinding goes here
End If
 
G

Guest

have you forgotten the IsPostBack check ?

the code should look like

if(!Page.IsPostBack())
{
// code to databind lstCompanies...
}
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top