I had ddl which in selected changed it execute some code
but when i tried to do that it wasn’t worked well WHEN i checked the reason i found that ddl in selected value =0 also i made all well and this is my code
protected void DDlProductFamily_SelectedIndexChanged(object sender, EventArgs e)
{
if (DDlProductFamily.DataValueField.Contains("ProductCategory_Id"))
using (SqlConnection Con = Connection.GetConnection())
{
SqlCommand Com = new SqlCommand("GetListViewByProductCategory", Con);
Com.CommandType = CommandType.StoredProcedure;
Com.Parameters.Add(Parameter.NewInt("@ProductCategory_Id", DDlProductFamily.SelectedValue.ToString()));
SqlDataAdapter DA = new SqlDataAdapter(Com);
DA.Fill(dt);
DataList1.DataSource = dt;
DataList1.DataBind();
}
}
The SelectedIndexChanged event fires on postback/callback. If you want it to fire when you actually select an item from a DropDownList, make sure you have AutoPostBack=”true”. For example:
<asp:DropDownList OnSelectedIndexChanged=”DDlProductFamily_SelectedIndexChanged” AutoPostBack=”true” …
If you don’t want it to fire when you select an item, then you must cause a postback (by clicking a button, etc…) after changing the selected item and it should fire.