GridView 编辑和删除的实现
GridView 中最常用的编辑和实现.
Aspx 前台:
<asp:CommandField ButtonType ="Button" HeaderText="修改" EditText ="修改" UpdateText ="更新" CancelText = "取消" ShowEditButton ="true" />
<asp:CommandField ShowDeleteButton="True" HeaderText="刪除" DeleteText ="刪除" ButtonType ="Button" />
后台方法:
删除:
gdvCondition_RowDeleting
{
删除逻辑
//再绑定
gdvCondition.EditIndex = -1
Me.BindEditGridView()
}
编辑:
gdvCondition_RowEditing
{
gdvCondition.EditIndex = e.NewEditIndex
Me.BindEditGridView()
}
取消:
gdvCondition_RowCancelingEdit
{
gdvCondition.EditIndex = -1
Me.BindEditGridView()
}
更新:
gdvCondition_RowUpdating
{
更新逻辑
gdvCondition.EditIndex = -1
Me.BindEditGridView()
}
BindEditGridView() 方法
{
gdvCondition.DataSource = dsCondition
gdvCondition.DataBind()
}