ankit gaur

ankit gaur

  • NA
  • 295
  • 30.5k

Multiple conditions in If Else in C#

Aug 24 2018 2:25 AM
Hello
 
I have four Dropdownlist and i want to show data in gridview.
when i select from ddlCategory[Dropdownlist] is not Null and other dropdown are null then i want to show only one category that time else return all the category.
But its showing all the category in if condition..plz help
 
 
 
con.Open();
if (ddlCategory.SelectedValue != "" && ddlSubCategory.SelectedItem.Text == "" && ddlBrand.SelectedItem.Text == "" && ddlItem.SelectedItem.Text == "")
{
SqlCommand cmd = new SqlCommand("select Distinct Category from tblMatCat where Category = @Category ", con);
cmd.Parameters.AddWithValue("@Category", ddlCategory.SelectedItem.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
else
{
SqlCommand cmd = new SqlCommand("select Distinct Category from tblMatCat ", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
 

Answers (7)