You didn't define the
i
you're using in the
if
line. Maybe that's outside of the code snippet you posted.
For me, it would be easier to read
for(int rowIndex = 1; rowIndex < GridView1.Rows.Count; i++)
{
if(GridView1.Rows[i - 1].Cells[4].Text == "Whatever")
{
DoSomething(GridView1.Rows[i - 1]);
}
}
But why would you want to start your iteration at
1
instead of the usual
0
and then always use
i - 1
? Is there more code that acutally uses
i
to do something to two adjacent rows?
Otherwise you would be better off starting at
0
and using just
i
.
Or forget about iteration variables altogether and use the
row
variable from your question's code.