Asp.net: select all the Repeater controls and Perform Batch operations. asp. netrepeater

Source: Internet
Author: User

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 ......}}}

 

        

 

Related Article

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.