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.