The example in this article describes how ASP.net uses the full selection in the Repeater control for bulk operations. Share to everyone for your reference. The specific analysis is as follows:
Today in the Repeater control encountered a full selection of operations, so the Internet check, find a feel better, then recorded,
After the interface code is simplified (select all operations):
Copy Code code 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.exec (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> Options </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/select Onclick= ' SelectAll" (This, "checkbox_id", "repeater_xx") ' />
<input class= "Anniu" id= "Input_gs" type= "Submit" runat= "Server" onserverclick= "Gssubmit_click" value= "Operation"/>
The background gets the data for the current row based on the selection and then operates
Copy Code code as follows:
public void Gssubmit_click (object sender, EventArgs e)
{
for (int i = 0; i < repeater_xx. Items.Count; i++)
{
Get check box
CheckBox cb = (checkbox) Rpt_paper.items[i]. FindControl ("Checkboxcz");
Determine whether or not to be selected
if (CB!= NULL && CB. Checked = = True)
{
Label ID = (label) rpt_paper.items[i]. FindControl ("lable_id");
Get the row ID
int id= Convert.ToInt32 (id.text);
Appropriate action
......
}
}
}
I hope this article will help you with the ASP.net program design.