7
Answers

Multiple conditions in If Else in C#

ankit gaur

ankit gaur

6y
762
1
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)