0
如何檢查和取消選中單個複選框檢查上的所有asp.net複選框?如何檢查並取消選中單個複選框檢查中的所有asp.net複選框?
我對Web窗體5 asp.net複選框我希望在1個單複選框,然後選中所有複選框將被cchecked如果複選框的勾選,那麼所有checkb牛,將取消選中..
如何檢查和取消選中單個複選框檢查上的所有asp.net複選框?如何檢查並取消選中單個複選框檢查中的所有asp.net複選框?
我對Web窗體5 asp.net複選框我希望在1個單複選框,然後選中所有複選框將被cchecked如果複選框的勾選,那麼所有checkb牛,將取消選中..
一點的代碼片段:
<asp:CheckBoxList ID="chkStatu" runat="server" RepeatDirection="Horizontal">
</asp:CheckBoxList>
<hr />
<asp:CheckBox ID="chkAll" runat="server" onclick="javascript:SelectAllCheckboxes(this,'chkStatu');"
Text="SelectAll" />
和js
function SelectAllCheckboxes(spanChk,str)
{
// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
var control;
xState=theBox.checked;
elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
control =elm[i].id.indexOf(str);
if(elm[i].checked!=xState && control != -1)
{
elm[i].click();
}
}
}
enter code here 'Check or UnCheck all the checkboxes based on header checkbox and change row color
Protected Sub ckHeader_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim chHeader As CheckBox
Dim chSelect As CheckBox
Dim cHeader As Boolean
Dim count As Integer
Dim gvr As DataGridItem
count = -1
Try
chHeader = CType(CMSgrid.Controls(0).Controls(1).FindControl("ckHeader"), CheckBox)
cHeader = chHeader.Checked
For Each gvr In CMSgrid.Items
count = count + 1
chSelect = CType(gvr.FindControl("ckSelect"), CheckBox)
If (cHeader = True) Then
gvr.BackColor = Color.Gold
gvr.ForeColor = Color.Black
chSelect.Checked = True
Else
If (count Mod 2) = 0 Then
gvr.BackColor = Color.LightGoldenrodYellow
gvr.ForeColor = Color.Black
Else
gvr.BackColor = Color.PaleGoldenrod
gvr.ForeColor = Color.Black
End If
chSelect.Checked = False
End If
Next
Catch ex As Exception
UserMsgBox(ex.Message)
WriteToLog(ex.Message)
End Try
End Sub
通過遵循甲Bove代碼,你可以理解如何做到這一點。 chHeader指示主複選框。