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

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

  3. Stuart Shay

    Neil Guest

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

    Darkmoor

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

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,736
    MattC
    Mar 22, 2005
  2. =?Utf-8?B?TWF4IFdlZWJsZXI=?=

    Alternating Item Style "ForeColor" not working in Template Column

    =?Utf-8?B?TWF4IFdlZWJsZXI=?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    1,142
    =?Utf-8?B?TWF4IFdlZWJsZXI=?=
    Oct 27, 2005
  3. Jason James

    Rows the rows of a grid view?

    Jason James, Aug 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    601
    Jason James
    Aug 10, 2006
  4. Seema Multani

    Clickable rows in Grid View

    Seema Multani, Aug 28, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    626
    Mark Rae
    Aug 29, 2006
  5. Replies:
    3
    Views:
    810
  6. Sachin
    Replies:
    1
    Views:
    505
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jun 1, 2007
  7. MangroveRoot

    alternating text/image rows

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