I am having a problem with an ASP.NET DropDownList which is populated by an XML file:
rblState.DataSource = dsState;
rblState.DataValueField = "abbreviation";
rblState.DataTextField = "name";
rblState.DataBind();
This works fine and displays all the right data however, the problem occurs when I try and retrieve the selected value from the list after a button has been clicked:
string state = rblState.SelectedItem.Text;
Console.WriteLine(state);
This always outputs only the first value within the list.
Anyone know the solution to this?
You are probably re-binding the
DataSourceon PostBack. Instead, do this: