drop down list checked
I had Drop down list which execute code when specific condition and I tried to check it through selected value but it get error
protected void DDLProductFamily_SelectedIndexChanged(object sender, EventArgs e)
{
if (DDLProductFamily.Items.FindByText("Name").Selected == true)
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();
}
else if (DDLProductFamily.Items.FindByText("ProductFamilly").Selected == true)
{
using (SqlConnection Con = Connection.GetConnection())
{
SqlCommand Com = new SqlCommand("GetListViewByProductFamily", Con);
开发者_Python百科 Com.CommandType = CommandType.StoredProcedure;
Com.Parameters.Add(Parameter.NewInt("@ProductFamily_Id", DDLProductFamily.SelectedValue.ToString()));
SqlDataAdapter DA = new SqlDataAdapter(Com);
DA.Fill(dt);
DataList1.DataSource = dt;
DataList1.DataBind();
}
}
}
Have you instantiate your dt
object?
ProductFamily is spelled wrong ( 2 l's instead of 1) so you're getting a null reference:
else if (DDLProductFamily.Items.FindByText("ProductFamilly").Selected == true)
You might need to check the ListeItemCollection method FindByText.
DDLProductFamily.Items.FindByText("Name").Selected
DDLProductFamily.Items.FindByText("ProductFamilly").Selected
If an item is not found in the collection using the "Name" or "ProductFamilly" criteria, null is returned. So if you call "Selected" on a null object, it will throw a null reference exception.
精彩评论