Object reference not set to an instance of an object

Ruslan's ASP .NET weblog

October 2008 - Posts

GridView RowDataBound Alternating Row RowState issue

This was pissing me off for a good hour: RowDataBound event after you call edit on a row, I was checking for this row's state like this:

e.Row.RowState == DataControlRowState.Edit

this worked fine with rows No 1, 3, 5... (non-alternating rows), however with alternating rows of same GridView it did NOT work as their RowState is something like "Alternate | Edit". RowState contains more than one value using bit-logic. See DataControlRowState Enumeration

the solution is as follows:

((e.Row.RowState & DataControlRowState.Edit) > 0)

A triangle in html

Guess how? No image involved, pure html!

Posted: Oct 23 2008, 02:57 PM by funky_rus | with 1 comment(s)
Filed under: ,
More Posts