GridView控件的数据删除
protectedvoidGridView1_RowDeleting(objectsender,GridViewDeleteEventArgse){SqlConnecti...
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection conn = new SqlConnection("server=.;database=Graduation Design;uid=sa;pwd=sa");
string mystr = "delete from givejob where givejobID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand cmd = new SqlCommand(mystr, conn);
conn.Open();
...............
...............
cmd.ExecuteNonQuery();
conn.Close();
bind();
}
我想在删除数据的时候弹出提示框,等用户确认之后再删除数据,请问代码是否应该加在省略号的位置?该如何写代码? 展开
{
SqlConnection conn = new SqlConnection("server=.;database=Graduation Design;uid=sa;pwd=sa");
string mystr = "delete from givejob where givejobID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand cmd = new SqlCommand(mystr, conn);
conn.Open();
...............
...............
cmd.ExecuteNonQuery();
conn.Close();
bind();
}
我想在删除数据的时候弹出提示框,等用户确认之后再删除数据,请问代码是否应该加在省略号的位置?该如何写代码? 展开
1个回答
2009-04-25
展开全部
用模板列实现,在模板列中添加button按钮,然后在GridView on RowCommand事件中作删除,用e.CommandName确定你的删除事件,可以把主键绑定为Button的 CommandArgment .页面上代码,
<asp:Button runat="server" Text="删除" OnClientClidk=OnClientClick='javascript:if(confirm("确认删除数据?")){ form.submit();}else return false;'/>
<asp:Button runat="server" Text="删除" OnClientClidk=OnClientClick='javascript:if(confirm("确认删除数据?")){ form.submit();}else return false;'/>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询