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:
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:
The code will execute even if rowstate is Alternate|Edit. It will ignore the alternate value.
Reference: ASP.NET Forum
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; }
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"); cashRec.Text = string.Empty; }
Reference: ASP.NET Forum
I have done the same thing but the problem is in edit mode its not even going in rowdatabound function
ReplyDeleteHi Danial,
DeleteThis solution should work given the succeeding rows are in Alternate|Edit mode. Try debugging the rowdatabound event to check the rowstate of the succeeding rows.