如何在gridview中删除之前确认用户 [英] How to confirm user before deletion in gridview
本文介绍了如何在gridview中删除之前确认用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在有删除命令字段我希望用户在删除数据前确认。
以下是我的代码:
Hi,
I have delete command field now i want user to confirm before deletion of data.
Below is my code:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false"
DataKeyNames="empid" OnPageIndexChanging="GridView2_PageIndexChanging"
OnRowCancelingEdit="GridView2_RowCancelingEdit" OnRowDeleting="GridView2_RowDeleting"
OnRowEditing="GridView2_RowEditing" OnRowUpdating="GridView2_RowUpdating"
style="margin-left: 445px">
<Columns>
<asp:BoundField DataField="empid" HeaderText="emp_id" />
<asp:BoundField DataField="empname" HeaderText="emp_name" />
<asp:BoundField DataField="empcity" HeaderText="emp_city" />
<asp:CommandField ShowEditButton="true" />
<asp:CommandField ShowDeleteButton="true" />
</Columns>
</asp:GridView>
------ -------------------------------------
删除代码:
-------------------------------------------
Delete code:
//gettting unqiue key from gridview as Datakey
int empid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
conn.Open();
SqlCommand chk = new SqlCommand("delete FROM emp where empid=@empid", conn);
chk.Parameters.AddWithValue("@empid", empid);
chk.ExecuteNonQuery();
conn.Close();
Bind();
推荐答案
参考 ASP.Net GridView - 删除行确认 [ ^ ]。
这篇关于如何在gridview中删除之前确认用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文