asp.net implementation of the batch deletion of the full selection of features case

Source: Internet
Author: User
<asp:gridview id= "GridView1" runat= "Server" autogeneratecolumns= "False"
Datakeynames= "Areaid" datasourceid= "SqlDataSource1" >
<Columns>
<asp:boundfield datafield= "Areaid" headertext= "Areaid" readonly= "True"
sortexpression= "Areaid"/>
<asp:boundfield datafield= "AreaName" headertext= "AreaName"
sortexpression= "AreaName"/>
<asp:boundfield datafield= "pid" headertext= "pid" sortexpression= "pid"/>
<asp:TemplateField>
<ItemTemplate>
<asp:checkbox id= "Chk_del" runat= "server"/>//used to determine whether the row to be deleted
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:sqldatasource id= "SqlDataSource1" runat= "Server"
connectionstring= "<%$ connectionstrings:work_oaconnectionstring%>"
Selectcommand= "SELECT * from [area]" ></asp:SqlDataSource>

<asp:checkbox id= "Chk_js" runat= "Server" text= "All Selected (JS)" onclick= "SelectAll (This)"/>//through JS to select all

The JS function is defined 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>


tips for deleting buttons

<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 ("Select the record you want to delete.") ");
return result;
}
result = Confirm ("Are you sure you want to delete the selected records?") ");
return result;
}

The second way is to implement a full selection of server-side code

<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;
}

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.