在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
.aspx界面 复制代码 代码如下: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>DataList控件删除操作(支持批量删除)</title> <script type="text/javascript"> function CheckAll(Obj) { var AllObj = document.all; if (Obj.checked)//全选 { for (var i = 0; i < AllObj.length; i++) { if (AllObj[i].type == "checkbox") { AllObj[i].checked = true; } } } else//反选 { for (var i = 0; i < AllObj.length; i++) { if (AllObj[i].type == "checkbox") { AllObj[i].checked = false; } } } } </script> </head> <body> <form id="form1" runat="server"> <div> <fieldset style="text-align: center; width: 540px;"> <legend style=" text-align:center; ">使用Datalist删除数据(支持批量删除)</legend> <asp:DataList ID="DataList1" runat="server" onitemcommand="DataList1_ItemCommand" DataKeyField="id"> <HeaderTemplate> <div style="text-align:center"> <table border = "1" cellpadding="0" cellspacing="0" style=" font-size:12; width:500px" > <tr> <td style="width:100px">全选/反选<input id="Checkbox1" type="checkbox" name="全选" value="全选" onclick="return CheckAll(this)" title="全选" /></td> <td style="width:100px">用户编号</td> <td style="width:100px">用户昵称</td> <td style="width:100px">个性签名</td> <td style="width:100px">删除</td> </tr> </table> </div> </HeaderTemplate> <ItemTemplate> <div style="text-align:center"> <table border = "1" cellpadding="0" cellspacing="0" style=" font-size:12; width:500px" > <tr> <td style="width:100px"> <asp:CheckBox ID="CheckBox2" runat="server" /></td> <td style="width:100px"><asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'></asp:Label></td> <td style="width:100px"><asp:Label ID="Label2" runat="server" Text='<%# Eval("bg_name") %>'></asp:Label></td> <td style="width:100px"><asp:Label ID="Label3" runat="server" Text='<%# Eval("bg_p_autograph") %>'></asp:Label></td> <td style="width:100px"><asp:Button ID="btnDelete" runat="server" Text="删除" CommandName="delete" BorderStyle="None" onclientclick="return confirm("确认删除?");" /></td><%--请注意此处的CommandName命令--%> </tr> </table> </div> </ItemTemplate> <FooterTemplate> <div style="text-align:center"> <table border="1" cellpadding="0" cellspacing="0" style="font-size:12px; width:100%"> <tr> <td style="width:100%; text-align:center"> <asp:Button ID="btnPLDelete" runat="server" Text="批量删除" CommandName="pldelete" BorderStyle="None" onclientclick="return confirm("确认删除?");" /></td> </tr> </table> </div> </FooterTemplate> </asp:DataList> </fieldset> </div> </form> </body> </html> .cs界面 复制代码 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class _Default : System.Web.UI.Page ////得到Web.config 中的连接放在变量中
运行效果图: |
请发表评论