Search within Gridview based on search criteria
In other forum, one user asked me to search within Grid view , and its display only those rows which match with the search criteria. so I given some code like this:
Code Snippet :
// iterate through all rows
for (int j = 0; j < GridView1.Rows.Count; j++)
{
// iterate through all cols
for (int i = 0; i < GridView1.Columns.Count; i++)
{
//match each cell of row with search value
if (GridView1.Rows[j].Cells[i].Text.Contains("search criteria"))
{
//set visible true if match with criteria
GridView1.Rows[j].Cells[i].Visible = true;
break;
}
else
{
//set visible false if match with criteria
GridView1.Rows[j].Cells[i].Visible = false;
}
}
}
No comments:
Post a Comment