I want to duplicate the same functionality of the edit button using a single click anywhere in a GridView row.
The code below does this, but with a major problem: if the user clicks off of one textbox to the next, the edit command fires again, and the changes made to the previous textbox revert back to it's original value.
Any suggestions on how to fix this behaviour?
Or, is there a better approach to accomplishing this?
EDIT: This was resolved by adding a check for row.RowState.HasFlag( DataControlRowState.Edit )
. See code below:
protected override void Render( System.Web.UI.HtmlTextWriter writer )
{
foreach( GridViewRow row in gvwOrderItems.Rows )
{
if( row.RowType == DataControlRowType.DataRow &&
row.RowState.HasFlag( DataControlRowState.Edit ) == false )
{
// enable click on row to enter edit mode
row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink( gvwOrderItems, "Edit$" + row.DataItemIndex, true );
}
}
base.Render( writer );
}
Check for row.RowState.HasFlag( DataControlRowState.Edit )
.
protected override void Render( System.Web.UI.HtmlTextWriter writer )
{
foreach( GridViewRow row in gvwOrderItems.Rows )
{
if( row.RowType == DataControlRowType.DataRow &&
row.RowState.HasFlag( DataControlRowState.Edit ) == false )
{
// enable click on row to enter edit mode
row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink( gvwOrderItems, "Edit$" + row.DataItemIndex, true );
}
}
base.Render( writer );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With