The Problem of Selecting all checkboxs by clicking the checkbox of the column header

2 replies. Last post: September 2, 2011 12:35 AM by Handy Surya
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
xu guochunMember

Hi ,

   In the webgrid , when I want to select all checkboxs of a column through clicking the checkbox of the column header , I meet a problem . The picture in the attachment file describes this issue .

  In the foreground Program , I use the SelfReferencingSettings . When I click the checkbox of the column header to select all checkboxs of this column , the first layer checkboxs can be selected . If a parent row has some child rows , the checkbox of the parent row can be selected , but the checkboxs of these child rows can not be selected .

  The following is the key code of the foreground program .

 <ISWebGrid:WebGrid ID="WG1" runat="server" UseDefaultStyle="True" DefaultStyleMode="Win7"
            Height="100%" OnInitializeDataSource="WG1_InitializeDataSource" 
            OnBatchUpdate="WG1_BatchUpdate" >
   <RootTable GridLineStyle="NotSet" DataKeyField="ModuleGuid">
       <SelfReferencingSettings ChildDataMember="ParentModuleCode" Enabled="True"  
              IsTreeViewSelectionMode="false"ExpandColumnMember="ModuleName"             
                   ParentDataMember="ModuleCode" />
       <Columns>
       </Columns>
   </RootTable>
<LayoutSettings AllowSorting="Yes" AllowSelectColumns="Yes" AlwaysShowHelpButton="false"
      AllowEdit="Yes" AllowMultipleSelection="No" AllowColumnFreezing="No"   
     StatusBarVisible="true" AllowBatchUpdate="true" AutoHeight="true" AutoWidth="false"  
             AutoFitColumns="true"AllowGrouping="No" PagingMode="ClassicPaging"  
                 PagingLoadMode="Automatic" PagingSize="50">
     <ClientSideEvents OnAfterInitialize="WG1_OnAfterInitialize" 
                 OnRowContextMenu="WG1_OnRowContextMenu"
  OnEnterEditMode="WG1_OnEnterEditMode" OnAfterExitEditMode="WG1_OnAfterExitEditMode" />
     <TextSettings Language="UseCustom" UseLanguage="zh-CN">
     </TextSettings>
     <HeaderStyle CssClass="WG-Header" />
     <RowHeaderStyle CssClass="WG-RH">
     </RowHeaderStyle>
     <RowStyle CssClass="WG-Row"></RowStyle>
     <AlternatingRowStyle CssClass="WG-AR" />
     <SelectedRowStyle CssClass="WG-SR" />
     <LostFocusRowStyle CssClass="WG-LFR">
     </LostFocusRowStyle>
     <EditTextboxStyle CssClass="WG7W-ET">
     </EditTextboxStyle>
     <ClientSideEvents OnAfterInitialize="WG1_OnAfterInitialize"  
       OnRowContextMenu="WG1_OnRowContextMenu"OnCheckBoxClick="WG1_OnCheckBoxClick" />
     </LayoutSettings>
</ISWebGrid:WebGrid> 

  The following is the key code of  creating a column of webgrid .

   wgCol0 = new WebGridColumn();
   int Index = chkRoleList.Items.Count - RemoveCount;
   wgCol0.Caption = "完全公开" + "<input type=\"checkbox\" onclick=\"SelectAllColumn(this)\" name=\"" + Index + "_chk_完全公开_" + "\">";
   wgCol0.ColumnType = ColumnType.CheckBox;
   wgCol0.CellStyle.HorizontalAlign = ISNet.WebUI.HorizontalAlign.Center;
   wgCol0.Name = "完全公开";
   wgCol0.EditType = EditType.Checkbox;
   wgCol0.DataType = "System.Boolean";
   wgCol0.Width = 100;
   wgCol0.IsAutoWidth = false;
   wgCol0.AllowSorting = Sorting.No;
   wgCol0.DataMember = "完全公开";
   wgCol0.CellStyle.HorizontalAlign = ISNet.WebUI.HorizontalAlign.Center;
   WG1.RootTable.Columns.Add(wgCol0);

   The following is the javascript method of selecting all checkboxs by clicking the checkbox of the column header .

function SelectAllColumn(obj) {
            var grid = ISGetObject("<%= WG1.ClientID %>");
            var index = obj.name.split('_');
            var cellIndex = parseInt(index[0]) + 1;
            for (i = 0; i < grid.TotalLoadedRows; i++) {
                var row = grid.RootTable.GetRow(i);
                var cell = row.GetCells()[cellIndex];
                if (obj.checked) {
                    cell.SetValue(true, true);
                }
                else {
                    var cbxElement = cell.GetElement().childNodes[0];
                    cbxElement.click();
                    cbxElement.checked = false;
                }
                cell.ActivateEdit();
                grid.MarkEdit();
                grid.ExitEdit(1, 0, 0);
            }
        }

   Anyone can help me to solve this issue ? Thanks a lot !

All times are GMT -5. The time now is 3:15 AM.
Previous Next