<script language="javascript">
function select_deselectAll (chkVal, idVal) {
var frm = document.forms[0];
// Loop through all elements<BR>
for (i=0; i<frm.length; i++) {
// Look for our Header Template's Checkbox
if (idVal.indexOf ('CheckAll') != -1) {
// Check if main checkbox is checked, then select or deselect datagrid checkboxes
if(chkVal == true) {
frm.elements[i].checked = true;
}
else {
frm.elements[i].checked = false;
}
// Work here with the Item Template's multiple checkboxes
}
else if (idVal.indexOf ('DeleteThis') != -1) {
// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
if(frm.elements[i].checked == false) {
frm.elements[1].checked = false; //Uncheck main select all checkbox
}
}
}
}
</script>
然后checkbox这样定义的:
<asp:TemplateColumn HeaderText="aaa">
<HeaderTemplate>
<asp:CheckBox id="CheckAll" OnClick="javascript: return select_deselectAll (this.checked, this.id);"
runat="server"></asp:CheckBox><font face="Webdings" color="white" size="4">a</font>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id="DeleteThis" OnClick="javascript: return select_deselectAll (this.checked,this.id);"
runat="server"></asp:CheckBox>
</ItemTemplate>
function select_deselectAll (chkVal, idVal) {
var frm = document.forms[0];
// Loop through all elements<BR>
for (i=0; i<frm.length; i++) {
// Look for our Header Template's Checkbox
if (idVal.indexOf ('CheckAll') != -1) {
// Check if main checkbox is checked, then select or deselect datagrid checkboxes
if(chkVal == true) {
frm.elements[i].checked = true;
}
else {
frm.elements[i].checked = false;
}
// Work here with the Item Template's multiple checkboxes
}
else if (idVal.indexOf ('DeleteThis') != -1) {
// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
if(frm.elements[i].checked == false) {
frm.elements[1].checked = false; //Uncheck main select all checkbox
}
}
}
}
</script>
然后checkbox这样定义的:
<asp:TemplateColumn HeaderText="aaa">
<HeaderTemplate>
<asp:CheckBox id="CheckAll" OnClick="javascript: return select_deselectAll (this.checked, this.id);"
runat="server"></asp:CheckBox><font face="Webdings" color="white" size="4">a</font>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id="DeleteThis" OnClick="javascript: return select_deselectAll (this.checked,this.id);"
runat="server"></asp:CheckBox>
</ItemTemplate>