2011-03-07 170 views

回答

1

一點的代碼片段:

<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(); 
      } 
      } 
    } 
0
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指示主複選框。

相關問題