Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Grid View Event Not Working on Alternating Rows (http://www.velocityreviews.com/forums/t116270-grid-view-event-not-working-on-alternating-rows.html)

Stuart Shay 12-28-2005 03:15 AM

Grid View Event Not Working on Alternating Rows
 
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



Stuart Shay 12-29-2005 06:00 AM

Re: Grid View Event Not Working on Alternating Rows
 
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) */
}




"Stuart Shay" <sshay@yahoo.com> wrote in message
news:OdEC$z1CGHA.4000@TK2MSFTNGP10.phx.gbl...
> 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
>
>




Neil 01-08-2008 11:10 PM

RE: Grid View Event Not Working on Alternating Rows
 
Hi.

All I can say is thank you and I totally agree. I have searched the web for examples of how to achive this, but yours is the ownly article I have found.

Many thanks.

Neil

From http://www.developmentnow.com/g/8_20...nating-Rows.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com

Darkmoor 08-20-2010 11:45 AM

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.)


All times are GMT. The time now is 07:46 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.