T
TB
Hi All:
The following is probably a newbie question, but please bear with me:
I am populating a drop down list with items from a database, and would
the default selected item to be the current value of the corresponding
field. I am doing something like this:
ddlexample.DataSource = mydatareader
ddlexample.DataValueField = "ID"
ddlexample.DataTextField = "Name"
ddlexample.SelectedIndex =
ddlexample.Items.IndexOf(ddlexample.Items.FindByValue(currvalue))
ddlexample.DataBind()
the variable "Currvalue" contains the current value of "ID"
But the result is that the first item of the list is always displayed
as the selected item, not the one the corresponds to the actual value
of the field "ID"
What I am doing wrong here?
Thanks
TB
The following is probably a newbie question, but please bear with me:
I am populating a drop down list with items from a database, and would
the default selected item to be the current value of the corresponding
field. I am doing something like this:
ddlexample.DataSource = mydatareader
ddlexample.DataValueField = "ID"
ddlexample.DataTextField = "Name"
ddlexample.SelectedIndex =
ddlexample.Items.IndexOf(ddlexample.Items.FindByValue(currvalue))
ddlexample.DataBind()
the variable "Currvalue" contains the current value of "ID"
But the result is that the first item of the list is always displayed
as the selected item, not the one the corresponds to the actual value
of the field "ID"
What I am doing wrong here?
Thanks
TB