Asp.net: select all the Repeater controls and Perform Batch operations. asp. netrepeater
Today, I encountered an all-selected operation in the Repeater control, so I checked it online and found one that I thought it was better. Then I recorded it,
After the interface code is simplified (select all ):
<Script type = "text/javascript"> function SelectAll (parentChk, ChildId, bigControlID) {var oElements = document. getElementsByTagName ("INPUT"); var bIsChecked = parentChk. checked; for (I = 0; I <oElements. length; I ++) {if (IsCheckBox (oElements [I]) & IsMatch (oElements [I]. id, ChildId, bigControlID) {oElements [I]. checked = bIsChecked ;}}}
Function IsMatch (id, ChildId, controlID) {var sPattern = '^' + controlID + '_ +. * '+ ChildId +' $ '; var oRegExp = new RegExp (sPattern); if (oRegExp.exe c (id) return true; else return false;} function IsCheckBox (chk) {if (chk. type = 'checkbox') return true; else return false ;}</script> <asp: repeater ID = "Repeater_xx" runat = "server"> <HeaderTemplate> <table> <tr> <th> Option </th> <th> data </th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <asp: checkBox ID = "CheckBox_ID" runat = "server" Checked = "false"/> </td> <asp: label runat = "server" ID = "Label_ID" Text = '<% # Eval ("Label_ID") %>'> </asp: label> </td> <tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp: Repeater> <asp: checkBox runat = "server" ID = "CheckBoxCz" Text = "select all/invert" onclick = 'selectall (this, "CheckBox_ID", "Repeater_xx") '/>
<Input class = "anniu" id = "input_gs" type = "submit" runat = "server" onserverclick = "Gssubmit_Click" value = "operation"/>
The background obtains the data of the current row based on the selected items and then performs operations
Public void Gssubmit_Click (object sender, EventArgs e) {for (int I = 0; I <Repeater_xx.Items.Count; I ++) {// obtain the check box CheckBox cb = (CheckBox) rpt_Paper.Items [I]. findControl ("CheckBoxCz"); // you can check whether the selected if (cb! = Null & cb. checked = true) {Label id = (Label) rpt_Paper.Items [I]. findControl ("Lable_ID"); // obtain the ID of the row int ID = Convert. toInt32 (Id. text); // corresponding operation ......}}}