且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用删除按钮删除gridview中的行

更新时间:2022-01-13 06:57:52

你可以在Code项目中看到一个帖子,它可以让你轻松删除,只需参考这个 -



网格查看删除,确认 [ ^ ]
U can see a post in Code project itself which will let you do that deletion easily, Just refer this-

GridView Delete, with Confirmation[^]


您可以在网格视图中添加模板字段,并在其中添加一个带有命令参数属性的链接按钮并将值设置为项目ID或KeyName,然后在网格的RowCommand中,使用以下代码:

you can add a template field to your grid view and in that add a link button with command argument attribute and set the value to the item ID or KeyName, and then in RowCommand of grid, use this code:
int id = Convert.ToInt32(e.CommandArgument);



它真正依据你的数据访问逻辑来处理删除事件!

for me我使用linq到EF并只调用deleteObject方法。



确认使用onclientclick属性并使用此代码:


its realy base on your data access logic to how to handle the delete event!
for me I use linq to EF and just call the deleteObject method.

for confirmation use onclientclick attribute and use this code:

<asp:LinkButton ID="LinkButton1" OnClientClick="confirm(are you sure to delete this record"

 CommandArgument='<%#Eval("id") %>' runat="server">delete</asp:LinkButton>


请参考类似的问答:

^ ]

如何从gridview中删除行。 [ ^ ]

使用复选框删除gridview中的记录 [ ^ ]
Please refer similar Q/A:
How to Delete a Row in gridview[^]
how to delete the row from gridview.[^]
delete records in gridview using checkbox[^]