开发者

Cancel a Gridview edit during the ObjectDataSource updated event

开发者 https://www.devze.com 2023-03-18 05:23 出处:网络
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 t

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 fail开发者_开发知识库s.


Very simply, you can keep the edit mode e.KeepInEditMode = true;

protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
    e.KeepInEditMode = true;
}


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消