GridView Select Record at the same time confirm user Confirm Delete _ Practical tips

Source: Internet
Author: User
User's actions give the user a prompt to confirm the deletion before deleting the record. Under normal circumstances, a record of a record deletion is no problem. However, if you encounter multiple selections, if the user does not select a record, go directly to the point to remove the ammonium button, it will first prompt to delete the confirmation before the message, and then prompts the user did not select the record you want to delete.

Insus.net want to achieve is to change the order of it, first of all to determine whether the user has a choice of records, if not, prompts the user to select records, once there is a select record, before you are prompted to delete the confirmation information.

The following example will be the first example of the GridView to place a checkbox, allow the user to select multiple records, and then leave a Delete ammonium button on the GridView.
Demo: http://www.jb51.net/article/33564.htm
Xxx.aspx:
Copy Code code as follows:

<asp:button id= "Buttondelete" text= "Delete" runat= "Server" onclick= "Buttondelete_click"
Causesvalidation= "false"/>
<asp:gridview id= "Gvcuttertype" runat= "Server" datakeynames= "Cuttertypeid" autogeneratecolumns= "false" >
<Columns>
<asp:TemplateField>
<itemstyle borderwidth= "1" bordercolor= "#c0c0c0" width= "1%"/>
<ItemTemplate>
<asp:checkbox id= "CheckBox1" runat= "Server" onclick= "Javascript:changerowbgcolor (This)"/>
</ItemTemplate>
</asp:TemplateField>
<!--
Other column TemplateField
-->
</Columns>
</asp:GridView>

Xxx.aspx.cs:
Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
This. BUTTONDELETE.ATTRIBUTES.ADD ("onclick", "return Confirmondelete ();");
}
protected void Buttondelete_click (object sender, EventArgs e)
{
Do delete something
}

Javascript:
Copy Code code as follows:

function Confirmondelete () {
if (document.getElementById ("<%= Gvcuttertype.clientid%> ") = = null) {
return false;
}
var objgv = document.getElementById ("<%= gvcuttertype.clientid%>");
var rc = objgv.rows.length;
var y = 0;
for (var i = 0; i < RC; i++) {
var getinput = objgv.rows[i].cells[0].getelementsbytagname ("input");
if (Getinput[0].type = = "checkbox") {
if (getinput[0].checked) {
y = y + 1;
}
}
}
if (y <= 0) {
Alert ("First select the record you want to delete.") ");
return false;
}
if (confirm) the record selected below will be deleted. ") = = True)
return true;
Else
return false;
}

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.