gridview编辑、删除
access数据库,user表,idname两个字段分别为1;张三。2;李四拖一个gridview到页面,绑定数据源,我怎么写编辑和删除的方法?听别人说要设ID为主键。高...
access数据库,user表,id name两个字段分别为1;张三。2;李四
拖一个gridview到页面,绑定数据源,我怎么写编辑和删除的方法?听别人说要设ID为主键。高手给写个详细点的例子,谢谢了。 展开
拖一个gridview到页面,绑定数据源,我怎么写编辑和删除的方法?听别人说要设ID为主键。高手给写个详细点的例子,谢谢了。 展开
2个回答
展开全部
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="6" ForeColor="#333333" GridLines="None" OnRowDeleting="GridView1_RowDeleting"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="name" HeaderText="姓名" ReadOnly="True" />
<asp:CommandField UpdateText="保存" ShowEditButton="True" CancelText="取消" DeleteText="删除" EditText="编辑" >
</asp:CommandField>
<asp:CommandField DeleteText="删除" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//删除
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//编辑
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//取消(编辑)
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//保存(编辑)
}
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="name" HeaderText="姓名" ReadOnly="True" />
<asp:CommandField UpdateText="保存" ShowEditButton="True" CancelText="取消" DeleteText="删除" EditText="编辑" >
</asp:CommandField>
<asp:CommandField DeleteText="删除" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//删除
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//编辑
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//取消(编辑)
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//保存(编辑)
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询