All-In/All-select for checkbox with repeater combined with JS in ASP.

Source: Internet
Author: User

Front Interface code:

<inputname= "Checkall"type= "checkbox"ID= "Checkall"value=""onclick= "Javascript:formselectall (' Form1 ', ' Cboxi ', ' Checkall ', this);" />//used to select whether the check box is all selected, using the JavaScript function "Formselectall (' Form1 ', ' checkbox ', this); "To achieve the full-selection effect, the specific parameters are explained in detail below<formID= "Form1"runat= "Server"> <Asp:repeaterID= "Rptlist"runat= "Server" > <ItemTemplate> <inputname= "Cboxi"ID= "Cboxi"runat= "Server"type= "checkbox"value= ' <%#Databinder.eval_r (Container.DataItem, "f_jobid")%>'/>//Use the Repeater control to bind the checkbox control to select individual content</ItemTemplate> </Asp:repeater>   </form>

Here is the JS code:

//Select All//formId: The form where the target check box is located//elename: Target's check box name//cballelename: check box ID for select all/not select AllfunctionFormselectall (FormId, Elename,cballeleid, e) {varElements = document.getElementById (formId). Elements;//get the form of the target check box     for(vari = 0; i < elements.length; i++) {        if(Elements[i].type = = "checkbox" && elements[i].name.indexof (elename) >= 0) {            if(document.getElementById (Cballeleid). Checked) {elements[i].checked= e.checked;//Select All            }            Else{elements[i].checked=false;//all do not choose            }                    }    }}

Here is the C # code:

 for (int0this.) RptList.Items.Count; i++)     {      = (htmlinputcheckbox)this. Rptlist.items[i]. FindControl ("cboxi");         if true       {           // If this check box is selected, then ...     }  }

All-In/All-select for checkbox with repeater combined with JS in ASP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.