if (i == 1) //if dropdown #1 index > 0
{
strSelectedType = ViewState["EN"].ToString();
strSelectedCol = "Name";
}
if (i == 2) //if dropdown #2 index > 0
{
strSelectedType = ViewState["SU"].ToString();
strSelectedCol = "Super";
}
if (i == 3) //if dropdown #3 index > 0
{
strSelectedType = ViewState["DT"].ToString();
strSelectedCol = "Deran";
}
if (i == 4) //if dropdown #4 index > 0
{
strSelectedType = ViewState["PR"].ToString();
strSelectedCol = "PRate";
}
DataTable dtTest = new DataTable();
dtTest = (DataTable)ViewState["gvDataTable"];
DataTable selectedTable = dtTest.AsEnumerable()
.Where(r => r.Field<string>(strSelectedCol) == strSelectedType)
.CopyToDataTable();
The above code is only using one column to filter.
How can I modify the dtText.AsEnumerable() so that it will filter like this:
DataTable selectedTable = dtTest.AsEnumerable()
.Where(if (dropdown #1 > 0) {r => r.Field<string>(strSelectedCol) == strSelectedType }
if (dropdown #2 > 0) { r => r.Field<string>(strSelectedCol) == strSelectedType }
if (dropdown #3 > 0) { r => r.Field<string>(strSelectedCol) == strSelectedType }
if (dropdown #4 > 0) { r => r.Field<string>(strSelectedCol) == strSelectedType })
.CopyToDataTable();
It will iterate through each dropdown append filter if the selected index > 0.
icannot be equal to two different values at same time. What is condition for filtering by several columns?