Code In Gridview RowDatabound Not Working If Rowstate Is Alternate|Edit In ASP.NET Web Forms
In a gridview rowdatabound event I have this condition to check if rowstate is in edit mode: if (e.Row.RowState == DataControlRowState.Edit) //row is in edit mode { TextBox actdaterec = (TextBox)e.Row.Cells[1].FindControl( "txtDateRec" ); actdaterec.Text = string .Empty; TextBox cashRec = (TextBox)e.Row.Cells[2].FindControl( "txtCashReceived" ); cashRec.Text = string .Empty; } The code above usually works if the rowstate is in edit mode, however on the succeeding rows the rowstate becomes Alternate|Edit . The code above does not work. So the solution would involve C# bitwise operator (&) . See the revised code below: if ((e.Row.RowState & DataControlRowState.Edit) > 0) //row is in edit mode { TextBox actdaterec = (TextBox)e.Row.Cells[1].FindControl( "txtDateRec" ); actdaterec.Text = string .Empty; TextBox cashRec = (TextBox)e.Row.Cells[2].FindControl( "txtCashReceived"