Grid View Event Not Working on Alternating Rows

Discussion in 'ASP .Net' started by Stuart Shay, Dec 28, 2005.

  1. Stuart Shay

    Stuart Shay Guest

    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, Dec 28, 2005
    #1
    1. Advertising

  2. Stuart Shay

    Stuart Shay Guest

    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" <> wrote in message
    news:OdEC$...
    > 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, Dec 29, 2005
    #2
    1. Advertising

  3. Stuart Shay

    Neil Guest

    Neil, Jan 8, 2008
    #3
  4. Stuart Shay

    Darkmoor

    Joined:
    Aug 20, 2010
    Messages:
    1
    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.)
    Darkmoor, Aug 20, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MattC
    Replies:
    0
    Views:
    1,584
    MattC
    Mar 22, 2005
  2. Jason James

    Rows the rows of a grid view?

    Jason James, Aug 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    391
    Jason James
    Aug 10, 2006
  3. Replies:
    3
    Views:
    599
  4. Sachin
    Replies:
    1
    Views:
    367
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jun 1, 2007
  5. MangroveRoot

    alternating text/image rows

    MangroveRoot, Nov 4, 2007, in forum: HTML
    Replies:
    7
    Views:
    424
    Adrienne Boswell
    Nov 4, 2007
Loading...

Share This Page