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