编辑索引更改时绑定数据 [英] binding data when edit index is changed

查看:70
本文介绍了编辑索引更改时绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gridview,我正在使用编辑按钮更新数据。



更新完成后我将网格重新放入编辑模式,但我需要在更新后绑定数据,所以问题是,当我在更新事件中使用此命令时:



GridView1.EditIndex = -1



网格不再处于更新模式,也不处于编辑模式,因此使用此命令将用于绑定数据的事件是什么:



GridView1.DataBind()



如果我在更改索引之前放入数据绑定,editIndex将不会更改..



非常感谢任何帮助!



谢谢..

解决方案

如果您想在更新行后触发 RowEditing ,请在 RowUpdating 活动。

<前lang =cs> 受保护 void GridView1_RowUpdating( object sender,GridViewUpdateEventArgs e)
{
// ......其他代码........... //

GridView1.EditIndex = -1;

// 更新后绑定GridView。
GridView1。的DataBind();

// 现在调用RowEditing事件。
GridView1_RowEditing( sender, new GridViewEditEventArgs(e.RowIndex));
}


I'm using a gridview and I'm updating the data using the edit button.

when the update is completed I'm putting the grid back to the edit mode but i need to bind the data after the update so the problem is that when i use this command in the updating event:

GridView1.EditIndex = -1

the grid is not in the updating mode anymore nor in the editing mode so what is the event that i should use to bind the data using this command:

GridView1.DataBind()

and if i put the databind before changing the index, the editIndex will not change..

any help is much appreciated !

thank you..

解决方案

If you want to fire RowEditing after updating the row, then do like below in RowUpdating Event.

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    //...... Other codes...........//
    
    GridView1.EditIndex = -1;
    
    // Binding the GridView after update.
    GridView1.DataBind();
    
    // Now call the RowEditing Event.
    GridView1_RowEditing(sender, new GridViewEditEventArgs(e.RowIndex));
}


这篇关于编辑索引更改时绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆