in dropdownlist selectedindexchanged event doesnt change its state

1.8k views Asked by At

In the following code everytime its taking only one item from dropdownlist. When I select any other item from dropdownlist its same as first item.

Please give solution

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    DataSet _subcat = new DataSet();
    _subcat = serviceus.Get_SERVICEUS_SUB_CATEGORYLIST(DropDownList1.SelectedValue.ToString());
    lbsubcategory.DataSource = _subcat.Tables[0].DefaultView;
    lbsubcategory.DataTextField = Convert.ToString(_subcat.Tables[0].Columns["CATEGORY_SUB1_NAME"].ColumnName);
    lbsubcategory.DataBind();
    Label5.Visible = true;
}
3

There are 3 answers

0
djeeg On

Do you have:

if(!IsPostBack) {
    DataBind();
}

around your initial databind (eg in OnLoad)

0
Canavar On

Check how you bind your dropdownlist. I think you're binding it everytime your page posts back to server. Try to use IsPostBack property of the page :

if (!IsPostBack){
   DropDownList1.DataSource = datasource;
   DropDownList1.DataBind();
}
0
Par6 On

EnableViewState="False" on the lbsubcategory.

Assuming AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"