Using multiple checks in gridview with Javascript.-VBForums
Results 1 to 1 of 1

Thread: Using multiple checks in gridview with Javascript.

Hybrid View

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    4,276

    Using multiple checks in gridview with Javascript.

    Ok since i see this question asked a lot of times i will put it here for future reference.
    So how would you create a column of checkboxes that will be checked and unchecked accordingly and also check all the checkboxes with one click.

    Use something like this on the gridview:
    Code:
      <Columns> .......etc
                     <asp:TemplateField>
                         <HeaderTemplate>
                             
                             <input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);"  runat="server" type="checkbox" />
                         </HeaderTemplate>
                         <ItemTemplate>
                             <asp:CheckBox ID="ChkboxUn" runat="Server" />
                         </ItemTemplate>
                     </asp:TemplateField>    
                      <asp:TemplateField>
                <HeaderTemplate>
    .....etc   </Columns>
    Then on the js function write:
    Code:
    function SelectAllCheckboxes(spanChk) {
          
            var oItem = spanChk.children;
    
            var theBox = (spanChk.type == "checkbox") ? spanChk : spanChk.children.item[0];
    
            xState = theBox.checked;
    
            elm = theBox.form.elements;
    
            for (i = 0; i < elm.length; i++)
    
                if (elm[i].type == "checkbox" && elm[i].id != theBox.id) {
    
                //elm[i].click();
    
                if (elm[i].checked != xState)
    
                    elm[i].click();
    
                //elm[i].checked=xState;
    
            }
    
        }
    Last edited by sapator; Aug 31st, 2011 at 09:11 PM.
    Slow as hell.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.