复制代码 代码如下:
<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 runat="server">
<div>
<fieldset>
<legend>使用Datalist删除数据(支持批量删除)</legend>
<asp:DataList runat="server"
onitemcommand="DataList1_ItemCommand" DataKeyField="id">
<HeaderTemplate>
<div>
<table border = "1" cellpadding="0" cellspacing="0" >
<tr>
<td>全选/反选<input type="checkbox" value="全选" title="全选" /></td>
<td>用户编号</td>
<td>用户昵称</td>
<td>个性签名</td>
<td>删除</td>
</tr>
</table>
</div>
</HeaderTemplate>
<ItemTemplate>
<div>
<table border = "1" cellpadding="0" cellspacing="0" >
<tr>
<td> <asp:CheckBox runat="server" /></td>
<td><asp:Label runat="server" Text='<%# Eval("id") %>'></asp:Label></td>
<td><asp:Label runat="server" Text='<%# Eval("bg_name") %>'></asp:Label></td>
<td><asp:Label runat="server" Text='<%# Eval("bg_p_autograph") %>'></asp:Label></td>
<td><asp:Button runat="server" Text="删除" CommandName="delete"
BorderStyle="None" onclientclick="return confirm("确认删除?");" /></td><%--请注意此处的CommandName命令--%>
</tr>
</table>
</div>
</ItemTemplate>
<FooterTemplate>
<div>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Button runat="server" Text="批量删除" CommandName="pldelete"
BorderStyle="None" onclientclick="return confirm("确认删除?");" /></td>
</tr>
</table>
</div>
</FooterTemplate>
</asp:DataList>
</fieldset>
</div>
</form>
</body>
</html>
.cs界面
复制代码 代码如下: