今天早上写了个小程序
是要将DataList里面的CheckBoxList全选
不多说了,代码如下
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<td colSpan="13">
<table border="1">
<TBODY>
<tr>
<td><asp:CheckBox ID="AllContentCheck" Text="全选" Runat="server" onclick="checkClick();"></asp:CheckBox></td>
<td>标题</td>
<td>详细内容</td>
</tr>
<asp:repeater id="RepeaterBankInfo" Runat="server">
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="BookContentCheck" Runat="server"></asp:CheckBox></td>
<td>
<asp:Label ID="lbTitle" Runat="server"></asp:Label></td>
<td>
<asp:Label ID="lbContent" Runat="server"></asp:Label></td>
</tr>
</ItemTemplate>
</asp:repeater></TBODY></table>
</td>
全选的Js代码如下
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<script language="javascript">
function checkClick()
{
var RowCnt=<%=rowsCount%>;
var IsChk;
IsChk = document.all.AllContentCheck.checked;
var i;
elem=window.Form1.elements;
for(i=0;i<elem.length;i++){
if (document.Form1.elements[i].type=="checkbox"){
document.Form1.elements[i].checked=IsChk;
}
}
}
</script>