dropDownList always returns 0 for selected index

  • Thread starter Thread starter Dica
  • Start date Start date
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
 
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
 
have you forgotten the IsPostBack check ?

the code should look like

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