I have a DropDownList which i am binding on page load. i dont have any buttons or anything. as soon as user selects the value in dropdown i need to show that value in label. i am not sure why this is not working. please help.
public string SelectedStore { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindStoresList();
}
}
protected void BindStoresList()
{ storeDDList.AppendDataBoundItems = true;
storeDDList.Items.Add(new ListItem("Select store", "-1"));
TempCollection stores = TempDataSource.LoadForCriteria("ALL", "Code ASC");
storeDDList.DataSource = stores;
storeDDList.DataTextField = "DisplayName";
storeDDList.DataValueField = "Code";
storeDDList.DataBind();
}
protected void storeDDList_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedStore = storeDDList.SelectedValue.ToString();
selectedItem.Text = SelectedStore;
}
I dont need any kind of jquery stuff as i am going to add gridview which binds depending on the value of dropdown..
****** EDITS *******
if i set AutoPostBack=True then on page refresh my DropDownList doesn’t bind at all as you can see in Page_Load Method, it will not call BindStoresList() method.
***** ANSWER *****
For people who might get stuck with this..
i was setting the EnableViewState to True for the DropDownList, so after page refreshes the SelectedValue was getting lost. after removing the EnableviewState and setting AutoPostBack to Ture working fine…
You have to set the
AutoPostBack=Truefor the dropdown, it will automatically send the call to server side without need to extra button.