hi guys,
i am working on a library automation system in ASP.NET with C#. I think this part of the forum is suitable.
When i come to my problem
in admin panel i designed a "Book Addition" page . In this part admin choose category and subcategory to add the book. The category names will be listed on Page_Load, admin chooses a category name and the subcategories which is related to the choosen category will listed on ddlSubcategory.
here is my code
Code:
int i;
protected void ddlCat_SelectedIndexChanged(object sender, EventArgs e)
{
ddlScat.Items.Clear();
SqlConnection connect = dbConnection.GetConnection();
SqlCommand cmd2 = new SqlCommand("select c_id from categories where c_name=@catname", connect);
cmd2.Parameters.AddWithValue("@catname", ddlCat.SelectedValue.ToString());
//cmd2.Parameters.AddWithValue("@catname", ddlCategory.SelectedItem.Value);
connect.Open();
SqlDataReader rdr2 = cmd2.ExecuteReader();
while (rdr2.Read())
{
i = Int32.Parse(rdr2.GetValue(0).ToString());
}
connect.Close();
connect.Open();
SqlCommand command2 = new SqlCommand("select s_name,s_id from subcategories where c_id=@i", connect);
command2.Parameters.AddWithValue("@i", i);
SqlDataAdapter da = new SqlDataAdapter(command2);
DataTable dt = new DataTable();
da.Fill(dt);
ddlScat.DataSource = dt;
ddlScat.DataTextField = "s_name";
ddlScat.DataValueField = "s_id";
ddlScat.DataBind();
connect.Close();
}
there is no warning or error. And Page_load part is working correctly but when i clicked ddlCat ( drop down list of Categories ) the ddlScat ' s( drop down list of subcategories ) items do not change.
i am waiting your answers..