Gridview实现删除一行?!!!
Gridview里面是写的后台代码和数据库连接的,想实现删除一行功能:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Update ")
{
Response.Redirect( "ReUser.aspx ");
}
else if (e.CommandName == "Delete ")
{
不知道代码怎么样写!(带弹出的对话框 "确定删除? ")
}
}
请教高手,谢谢
------解决方案--------------------btn_del.Attributes.Add( "onclick ", "javascript:return " + "confirm( '你确定要删除所选纪录? ') ");
------解决方案--------------------在前台 button控件的CommandArgument属性 绑定表的ID,然后在后台找到id就行了
例如
<asp:TemplateField HeaderText= "删除 ">
<ItemTemplate>
<asp:Button ID= "btnCancel " runat= "server " Text= "删除 " Width= "50 " CommandName= "mydelete " CommandArgument= ' <%# Bind( "BedMainConTentID ") %> ' CssClass= "ButtonCss " />
</ItemTemplate>
<ItemStyle Width= "50 " />
</asp:TemplateField>
protected void InformationGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (command == "mydelete ")
{
myBFBedState.EditBedStateCancel(Convert.ToInt32(e.CommandArgument));
}
}
------解决方案--------------------带弹出的对话框 "确定删除? "的方法应该在前台写,不是在后台写的
1、前台脚本
<script type= "text/javascript ">
function deleteinfo()
{
return window.confirm( '确定删除此记录吗? ');
}
</script>
2、
<asp:TemplateField HeaderText= "编辑 ">
<ItemTemplate>
<asp:Button ID= "Buttonedit " runat= "server " CommandName= "ClickEdit " CommandArgument= ' <%#Eval( "绑定表的主键 ") %> ' />
</ItemTemplate> </asp:TemplateField>
<asp:TemplateField HeaderText= "删除 ">
<ItemTemplate>
<asp:Button ID= "Buttondelete " runat= "server " OnClientClick= "return deleteinfo() " CommandName= "ClickDelete " CommandArgument= ' <%#Eval( "绑定表的主键 ") %> ' />
</ItemTemplate> </asp:TemplateField>
3、后台
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs