Asp.net Selects all the Repeater controls to operate instances in batches. asp. netrepeater

Source: Internet
Author: User

Asp.net Selects all the Repeater controls to operate instances in batches. asp. netrepeater

This example describes how to use asp.net to select all items in the Repeater control for batch operations. Share it with you for your reference. The specific analysis is as follows:

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 ):

Copy codeThe Code is as follows:
<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>
<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

Copy codeThe Code is as follows:
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 ");
// Determine whether the image is 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
......
}
}
}

I hope this article will help you design your asp.net program.

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.