ASP GridView控件绑定数据进行数据的增删改查

1、新建一个空项目,添加Web窗体FindUser,在前台设计中拖入GridView控件,在编辑列中设计BoundFieldHeaderText属性设置表头文本,DataField属性设置为要显示的数据库字段。
在这里插入图片描述
如果要加入修改,删除按钮,就再一次编辑列添加ButtonField,属性HeaderText设置表头文本,属性Text为样式显示的文字,设置各自的CommandName(Update、Delete)ButtonType也可以自己设置,可以是Button,也可以是超链接。
编辑列操作效果:
在这里插入图片描述
GridView控件中设置AutoGenerateColumns属性为false,添加事件OnRowDeletingOnRowUpdatingOnRowCommand
第一步结束后的前台代码:

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" OnRowUpdating="GridView1_RowUpdating">
       <Columns>
            <asp:BoundField HeaderText="序号" DataField="ID" ReadOnly="true"/>
            <asp:BoundField HeaderText="名称" DataField="Name" ReadOnly="true"/>
            <asp:BoundField HeaderText="作者" DataField="Author" ReadOnly="true"/>
            <asp:BoundField HeaderText="类型" DataField="Type" ReadOnly="true"/>
            <asp:ButtonField ButtonType="Button" HeaderText="删除功能" Text="删除" CommandName="Delete"/>
            <asp:ButtonField ButtonType="Button" HeaderText="修改功能" Text="修改" CommandName="Update"/>
 
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值