I have a drop down list populated from a database. When i use the dplTags.SelectedItem.Value it only returns the first value and not the one i selected?
Could Someone tel me where i’m going wrong?
When i call it:
String TagID = dplTags.SelectedItem.Value; // Will only select the first value????
It always returns the TagID of the first item, not the selected one :\
This is how i bind it:
using (var conn = new SqlConnection(Properties.Settings.Default.DBConnectionString))
{
conn.Open();
SqlDataAdapter daTags
= new SqlDataAdapter("Select * From Tag", conn);
DataSet dsTags = new DataSet("TagCloud");
daTags.FillSchema(dsTags, SchemaType.Source, "Tag");
daTags.Fill(dsTags, "Tag");
daTags.MissingSchemaAction = MissingSchemaAction.AddWithKey;
daTags.Fill(dsTags, "Tag");
DataTable tblTag;
tblTag = dsTags.Tables["Tag"];
dplTags.DataSource = dsTags;
dplTags.DataMember = "Tag";
dplTags.DataValueField = "TagID"; //Value Member
dplTags.DataTextField = "Value"; // Display Member
dplTags.DataBind();
}
Please help, Thanks in Advance.
Where are you binding data to these dropdown list controls? They should be bound only in the initial loading of the page as follows. I suspect that you are binding them in every page load and therefore selected values disappear.