asp.net use full selection in Repeater control for bulk Operation examples _ practical tips

Source: Internet
Author: User

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.

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.