I have a Gridview where I check the data of some determined cells during the OnDataBound event in order to trigger some action.
public void PaintRows_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells[0].Text == "0")
{
//first condition
}
else if (e.Row.Cells[0].Text == "1" && e.Row.Cells[12].Text.Length != 6)
{
//second condition
}
else
{
//launch the action
}
}
Even though all conditions are fulfilled, the action that is triggered by the else statement is always fired. I don't see any logic that explains that. I learned that looping through the rows the event binds the headers too and therefore I check this case in the conditions. But are there any other invisible rows that I am missing and that lead to the fact that the else condition is reached? I hope I did made my point clear. Martin
You mention that you’re checking to exclude the row if it's a header row, but haven’t provided what your actual conditional test is for this..
To pre-filter for only data rows, you would apply this condition:
if(e.Row.RowType == DataControlRowType.DataRow)