GridView 常用事件--删除,更新,删除,取消等
要设置的基本属性:DataKeyNames
前台代码:
Code
数据绑定:
Code
后台代码:
取消操作:
protected void GridViewID_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridViewID.EditIndex = -1;
this.MyDatabind();
}
{
GridViewID.EditIndex = -1;
this.MyDatabind();
}
更新操作:
更新操作
删除操作:
//用ButtonField要设置CommandName属性
设计器中Text:<div id="de" onclick="JavaScript:return confirm('确认要删除本条记录?')">删除</div>
(Text)代码请看上前台代码
Code
编辑操作:
protected void GridViewID_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridViewID.EditIndex = e.NewEditIndex;
this.GridViewID.EditRowStyle.BackColor = Color.AliceBlue;//设置编辑状态下的样式,要引入System.Drawing命名空间
this.MyDatabind();
}
{
this.GridViewID.EditIndex = e.NewEditIndex;
this.GridViewID.EditRowStyle.BackColor = Color.AliceBlue;//设置编辑状态下的样式,要引入System.Drawing命名空间
this.MyDatabind();
}