How To Check Combined RowState 'Altering | Edit 'in RowDataBound?

On my page, I configured a GridView with multiple columns. I encoded the update, delete and insert method. Although my GridView binds its data, the following method is called:

protected void GridViewAutomat_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if(e.Row.RowState != DataControlRowState.Edit)
        { 
            //some code

        }
    }
}

The problem with my second if statement is that when my GridView enters edit mode (when I want to update an entry in my GridView), it will not catch RowState Alternate | Edit , which looks like this (this is how RowState is after calling my update method):

When I try to combine the two RowStates separately, it will not work:

if(e.Row.RowState != DataControlRowState.Edit && 
   e.Row.RowState != DataControlRowState.Alternate)

if-statement , ( | ), !=

- , Alternate | ?

+4
1

:

  • :

    e.Row.RowState != DataControlRowState.Edit
    
  • | :

    e.Row.RowState != (DataControlRowState.Edit | DataControlRowState.Alternate)
    

:

if (e.Row.RowType == DataControlRowType.DataRow &&
    e.Row.RowState != DataControlRowState.Edit && 
    e.Row.RowState != (DataControlRowState.Edit | DataControlRowState.Alternate))
{ 
    //... Here is logic
}

:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    if (e.Row.RowState != DataControlRowState.Edit && 
        e.Row.RowState != (DataControlRowState.Edit | DataControlRowState.Alternate))
    {
        //... here is logic
    }
}
+1

Source: https://habr.com/ru/post/1685731/


All Articles