Выпадающий список для выбранного отдела не фильтруется
Привет я использовал 3 dropdownlist в виде сетки для фильтрации отдела Ddl не фильтрует отдел
Что я уже пробовал:
<pre>private void BindGrid() { DataTable dt = new DataTable(); string query = " select * from gvdetails17 WHERE 1=1 "; SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; if (ddlAddSalary1.SelectedValue != "" && ddlAddSalary1.SelectedValue != "--Select--") { string[] sal = ddlAddSalary1.SelectedValue.Split('-'); string from = sal[0]; string to = sal[1]; query += " and Sal between @fromsal and @tosal "; cmd.Parameters.AddWithValue("@fromsal", from); cmd.Parameters.AddWithValue("@tosal", to); } if (ddlAge.SelectedValue != "" && ddlAge.SelectedValue != "--Select--") { string[] age = ddlAge.SelectedValue.Split('-'); string from1 = age[0]; string to1 = age[1]; query += " and Age between @fromage and @toage "; cmd.Parameters.AddWithValue("@fromage", from1); cmd.Parameters.AddWithValue("@toage", to1); } if (ddlDepartment.SelectedValue == "") { cmd.Parameters.AddWithValue("@DepartmentName", ddlDepartment.SelectedValue); } cmd.CommandText = query; cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); gvDetails.DataSource = dt; gvDetails.DataBind(); } protected void txt_SearchName_TextChanged1(object sender, EventArgs e) { cn.Open(); SqlCommand cmd = new SqlCommand("select * from gvdetails17 where EmpName LIKE '% " + txt_SearchName.Text + "%'", cn); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); gvDetails.DataSource = dt; cn.Close(); }
protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); }