I am used RowDataBound event for a GridView control on my application. I want to detect the rows for edit mode to do some code in RowDataBound event. For which I wrriten the below code.
- if ((e.Row.RowState == DataControlRowState.Edit) && (e.Row.RowType == DataControlRowType.DataRow))
- {
-
- }
The above code worked fine only with Normal rows state(1, 3, 5... (non-alternating rows). But This piece of code not working if the row state is Alternate for edit mode (2,4,6.. (Alternating rows).
When I debug the code, the e.Row.RowState for alternate rows gives me the value something like "Alternate | Edit". That's means it RowState contains more than one value using bit-logic.
Solutions:
So, the solutions of above problem is to check the row state value as follows:
- if (((e.Row.RowState & DataControlRowState.Edit) > 0) && (e.Row.RowType == DataControlRowType.DataRow))
- {
- // Logic here.
- }