问题描述
我想在GridView行的任何地方使用一次单击来复制编辑按钮的相同功能。
下面的代码是这样做的,但有一个主要问题:如果用户点击一个文本框到下一个文本框,那么edit命令会再次触发,对上一个文本框所做的更改恢复为原始值。
有关如何解决此问题的任何建议?
或者,是否有更好的方法来完成这项工作?
编辑:通过添加
检查 row.RowState.HasFlag(DataControlRowState.Edit)。
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
foreach(GridViewRow (row.RowType == DataControlRowType.DataRow&&
row.RowState.HasFlag(DataControlRowState.Edit)== false)$ b $ {
if(row.RowType == DataControlRowType.DataRow&&
row.RowState.HasFlag(DataControlRowState.Edit)== false) b
//启用点击行进入编辑模式
row.Attributes [onclick] =
ClientScript.GetPostBackClientHyperlink(gvwOrderItemsEdit $+ row.DataItemIndex,true) ;
}
}
base.Render(writer);
}
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 ); }
这篇关于点击一个GridView行的任何地方进入编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!