Grid View Event Not Working on Alternating Rows

S

Stuart Shay

Hello All:

I am working on a ASP.NET GridView, I am not sure to correctly define the
condition so Alternating Rows are fired with in the event. My Code only
works on Item Rows in both Normal and Edit State.

protected void gvUserList_RowDataBound(object sender, GridViewRowEventArgs
e)
{

if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState ==
DataControlRowState.Normal)
{
}

if( e.Row.RowState == DataControlRowState.Edit)
{
}

}

Thanks
Stuart
 
S

Stuart Shay

I solved the problem would have been nice if MSFT provided this sample in
the documentation for binding a control (dropdown,checklist,etc) in a Edit
Mode for the GridView

if ((e.Row.RowState == (DataControlRowState.Edit |
DataControlRowState.Alternate)) || (e.Row.RowState ==
DataControlRowState.Edit))
{
/* Edit Mode Code Here (DataControlRowState.Edit) */
}
else if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState ==
DataControlRowState.Normal || e.Row.RowState ==
DataControlRowState.Alternate))
{
/* DataRow Mode Code Here (DataControlRowState.Normal) */
}
 
Joined
Aug 20, 2010
Messages
1
Reaction score
0
While the above will work, a more concise way of checking for the edit flag would be:

if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) {
// Editing
} else {
// Not editing
}

Note that the above uses a bitwise and (&) not a logical and (&&).

(I know, I know, I'm necro-posting, but I was trying to remember how to do this yesterday and stumbled across this post—I figured I'd share the bitwise-and method since this was one of the first few results that came up on Google.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top