The GridView pop-up prompt when using CommandField deletes, in the GridView provided by the. Net2005 we can add a CommandField directly to delete columns: <asp:commandfield showdeletebutton= "True"/>, finished deleting in its RowDeleting event. But in most of us do this delete operation need to first let the operator reconfirm, and then delete, in order to avoid misoperation caused by the deletion of the mistake.
You can add a confirmation dialog box before you delete the GridView by following this method.
First, click "Columns" in the GridView Properties box to enter its field designer. Then in the field designer, select the previously added CommandField "Delete" column, where you will see a "convert this segment to Templatefied" item under its list of properties and click Convert it to templatefied column.
After you exit the field designer, switch to Source view you will find that the column has been from the original: <asp:commandfield showdeletebutton= "True"/>
Changed into:
Copy Code code as follows:
<asp:templatefield showheader= "False" >
<ItemTemplate>
<asp:linkbutton id= "LinkButton1" runat= "Server" causesvalidation= "False" commandname= "delete" text= "Remove" ></ Asp:linkbutton>
</ItemTemplate>
Finally in <asp:LinkButton> add: onclientclick= "return confirm (' Confirm to delete?") ');"
Click Delete in this way will be on the client before "confirm to delete?" dialog box, and the code originally written in the RowDeleting event is completely unchanged.
The second method:
Implementation method:
Double-click the Onrowdatabound event of the GridView;
In the background The GridView1_RowDataBound () method adds code, and the final code looks like this:
Copy Code code as follows:
protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
{
If it is a bound data row
if (E.row.rowtype = = Datacontrolrowtype.datarow)
{
if (e.row.rowstate = = Datacontrolrowstate.normal | | e.row.rowstate = = datacontrolrowstate.alternate)
{
((LinkButton) e.row.cells[6]. Controls[0]). Attributes.Add ("onclick", "Javascript:return Confirm" (' You are sure to delete: \ "" + e.row.cells[1]. Text + "\"? ")");
}
}
}
These are two of the most common ways to refine the delete controls in the GridView, which have not yet implemented binding on specific data.