How to achieve the summary of the total selection method when deleting records in batches _ practical skills
Source: Internet
Author: User
Large batch of data deletion, if there is a full selection button to multiple pages displayed on the record all selected to delete that than a strip of the deletion of more humane, next to say how to achieve, in fact, a lot of articles on the Internet are said how to delete the bulk, can be divided into two major categories of 1: The use of JS script to achieve a full selection. 2: The server-side implementation of the full selection
First of all, say how to use JS to achieve a full selection
Drag a GridView to the page, set up the data source, add a template column to the GridView, and add a chekcbox to the template column, such as the following code
<asp:gridview id= "GridView1" runat= "Server" autogeneratecolumns= "False" datakeynames= "ProductID"
Datasourceid= "SqlDataSource1" >
<Columns>
<asp:boundfield datafield= "ProductID" headertext= "ProductID" insertvisible= "False"
Readonly= "True" sortexpression= "ProductID"/>
<asp:boundfield datafield= "ProductName" headertext= "ProductName" sortexpression= "ProductName"/>
<asp:boundfield datafield= "SupplierID" headertext= "SupplierID" sortexpression= "SupplierID"/>
<asp:boundfield datafield= "CategoryID" headertext= "CategoryID" sortexpression= "CategoryID"/>
<asp:TemplateField>
<ItemTemplate>
<asp:checkbox id= "Chk_del" runat= "Server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView> Add a CheckBox control to the Contacts page
<asp:checkbox id= "Chk_js" runat= "Server" text= "Select All (JS)" onclick= "SelectAll" (This)/>
and write the JS script for the control as follows: <script type= "Text/javascript" >
Sets the selected state of all the checkbox based on the checked state of the incoming checkbox
function SelectAll (obj)
{
var allinput = document.getelementsbytagname ("input");
alert (allinput.length);
var looptime = allinput.length;
for (i = 0;i < looptime;i++)
{
alert (Allinput[i].type);
if (Allinput[i].type = "checkbox")
{
allinput[i].checked = obj.checked;
}
}
}
</script> The basic effect is there, and then we're decorating it. Add a button to a Web page
<asp:button id= "btn_deleterecords" runat= "Server" onclientclick= "return Judgeselect ();" text= "Delete checked records"/>
Add JS Script
Determine if the record is checked and the user confirms the deletion
function Judgeselect ()
{
var result = false;
var allinput = document.getelementsbytagname ("input");
var looptime = allinput.length;
for (i = 0;i < looptime;i++)
{
if (allinput[i].checked)
{
result = true;
Break
}
}
if (!result)
{
Alert ("Please select the record you want to delete!") ");
return result;
}
result = Confirm ("Are you sure you want to delete the selected records?") ");
return result;
}
2 Implementing the full selection via server-side code
Add a checkbox to the page and set the AutoPostBack property to True and add a checkedchanged event to it
<asp:checkbox id= "Chk_server" runat= "Server" oncheckedchanged= "chk_server_checkedchanged" Text= "Select All (Server)" autopostback= "True"/>
The event code is as follows
int a = this. GridView1.Rows.Count;
for (int i = 0; i < A; i++)
{
CheckBox chk = (checkbox) this. Gridview1.rows[i]. FindControl ("Chk_del");
Chk. Checked = this.chk_Server.Checked;
}
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