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.