在 ObjectDataSource 更新事件期间取消 Gridview 编辑
在我的 Asp.net 网页中,我有一个 GridView 控件,该控件将数据绑定到 ObjectDataSource。用户可以直接在 GridView 中编辑行。有时更新会验证失败。发生这种情况时,我希望正在更新的行保持在编辑模式。
在 onUpdating 的事件处理程序中,事件 args 对象具有取消属性。但我需要检查 onUpdated 事件处理程序中的更新是否失败,并且它没有 e.Cancel 属性。
因此,我需要知道如何在更新失败时使 GridView 行保持在编辑模式。
In my Asp.net web page, I've got a GridView control that is data bound to an ObjectDataSource. The user can edit row directly in the GridView. There are times when the update fails validation. When this happens, I would like the row that was being updated to remain in the edit mode.
In the event handler for onUpdating, the event args object has a cancel property. But I need to check to see if the update failed in the onUpdated event handler, and it doesn't have e.Cancel property.
So I need to know how to get a GridView row to remain in edit mode if the update fails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很简单,保持编辑模式即可
e.KeepInEditMode = true;
Very simply, you can keep the edit mode
e.KeepInEditMode = true;
解决此问题的一种方法是使用验证控件,如果验证未通过,它将限制用户发送请求。
但是要保持gridview处于更新模式,您必须维护其编辑索引属性,因为当gridview不处于编辑模式时,通常其编辑索引设置为-ve值,但如果处于编辑模式,则gridview编辑索引设置为某个值正整数值。
您也可以参考这个链接:
http://msdn.microsoft.com /en-us/library/system.web.ui.webcontrols.gridviewupdatedeventargs.keepineditmode.aspx
One way to solve this problem is that you use Validation controls, which will restrict the user to send request if validation does not passes.
But to keep gridview in update mode, you must mantain its edit index property, because when gridview is not in edit mode usually its edit index is set to -ve value, but if it is in edit mode, gridview edit index is set to some positive integer value.
You could refer this link too:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewupdatedeventargs.keepineditmode.aspx
将 EditIndex 值保存在变量中。取消 gridview 更新 bu
GridView1.EditIndex=-1;
,然后为了使 Gridview 保持在编辑模式,您可以再次使用之前保存的索引值设置 EditIndex 值。save the EditIndex value in a variable. Cancel the gridview update bu
GridView1.EditIndex=-1;
and then to keep the Gridview in edit mode you can again set the EditIndex value with the previously saved index value.