Hi,
I would like to ask are there any other good way to revamp the following code?
Actually this is for filtering for 3 columns.
protected void ddlCat_SelectedIndexChanged(object sender, EventArgs e)
{
string ddlCat = ((DropDownList)sender).SelectedValue;
Session["ddlCat"] = ddlCat;
string ddlLoc = (string)Session["ddlLoc"];
string ddlStatus = (string)Session["ddlStatus"];
if (ddlCat == "All")
{
if (ddlLoc == "All")
{
if (ddlStatus == "All")
{
SqlDataSource1.SelectCommand = "SELECT manual_cat , process_loc , area , doc_no , rev , title , originator , mrc_no , effective, status FROM dbo.TrainningManual";
}
if (ddlStatus != "All")
{
SqlDataSource1.SelectCommand = "SELECT manual_cat , process_loc , area , doc_no , rev , title , originator , mrc_no , effective, status FROM dbo.TrainningManual WHERE status = '" + ddlStatus + "'";
}
}
if (ddlLoc != "All")
{
if (ddlStatus == "All")
{
SqlDataSource1.SelectCommand = "SELECT manual_cat , process_loc , area , doc_no , rev , title , originator , mrc_no , effective, status FROM dbo.TrainningManual WHERE process_loc = '" + ddlLoc + "'";
}
if (ddlStatus != "All")
{
SqlDataSource1.SelectCommand = "SELECT manual_cat , process_loc , area , doc_no , rev , title , originator , mrc_no , effective, status FROM dbo.TrainningManual WHERE process_loc = '" + ddlLoc + "' and status = '" + ddlStatus + "'";
}
}
}
else
{
if (ddlLoc != "All")
{
if (ddlStatus == "All")
{
SqlDataSource1.SelectCommand = "SELECT manual_cat , process_loc , area , doc_no , rev , title , originator , mrc_no , effective, status FROM dbo.TrainningManual WHERE manual_cat = '" + ddlCat + "' and process_loc = '" + ddlLoc + "' ";
}
if (ddlStatus != "All")
{
SqlDataSource1.SelectCommand = "SELECT manual_cat , process_loc , area , doc_no , rev , title , originator , mrc_no , effective, status FROM dbo.TrainningManual WHERE manual_cat = '" + ddlCat + "' and process_loc = '" + ddlLoc + "' and status = '" + ddlStatus + "' ";
}
}
if (ddlLoc == "All")
{
if (ddlStatus == "All")
{
SqlDataSource1.SelectCommand = "SELECT manual_cat , process_loc , area , doc_no , rev , title , originator , mrc_no , effective, status FROM dbo.TrainningManual WHERE manual_cat = '" + ddlCat + "'";
}
if (ddlStatus != "All")
{
SqlDataSource1.SelectCommand = "SELECT manual_cat , process_loc , area , doc_no , rev , title , originator , mrc_no , effective, status FROM dbo.TrainningManual WHERE manual_cat = '" + ddlCat + "' and status = '" + ddlStatus + "'";
}
}
}
GridView1.DataBind();
}