asp.net uses full selections in the Repeater control for bulk operation instances
- 2021-06-28 09:04:44
- OfStack
This article describes an example of how asp.net uses full selections in the Repeater control to do batch operations.Share it for your reference.Specific analysis is as follows:
Today, I encountered a fully selected operation in the Repeater control, so I checked it on the Internet and found a better one, so I wrote it down.
Once the interface code is simplified (all operations selected):
<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> 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 / Deselect " onclick='SelectAll(this,"CheckBox_ID","Repeater_xx")'/>
<input class="anniu" id="input_gs" type="submit" runat="server" onserverclick="Gssubmit_Click" value=" operation " />
Background retrieves data for the current row based on the selected item and then operates on it
public void Gssubmit_Click(object sender, EventArgs e)
{
for (int i = 0; i < Repeater_xx.Items.Count; i++)
{
// Get Checkboxes
CheckBox cb = (CheckBox)rpt_Paper.Items[i].FindControl("CheckBoxCz");
// Determine if 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);
// Corresponding actions
......
}
}
}
I hope that the description in this paper will be helpful to everyone's asp.net program design.