In the gridview, we can directly add a commandfield deletion column to delete a row. However, in order to avoid accidental deletion due to misoperations, the operator is asked to confirm the deletion before deletion.
First, we add a template column to our gridview, as shown below:
The following is a reference clip:
<Asp: templatefield headertext = "delete" showheader = "false">
<Itemstyle forecolor = "red"/>
<Itemtemplate>
<Asp: linkbutton id = "btndelete" runat = "server" causesvalidation = "false" commandname = "delete"
TEXT = "delete"> </ASP: linkbutton>
</Itemtemplate>
</ASP: templatefield> |
Next, we add onclientclick = "Return confirm ('Are you sure you want to delete this row? ') ", As follows:
The following is a reference clip:
<Asp: templatefield headertext = "delete" showheader = "false">
<Itemstyle forecolor = "red"/>
<Itemtemplate>
<Asp: linkbutton id = "btndelete" runat = "server" causesvalidation = "false" commandname = "delete"
TEXT = "delete" onclientclick = "Return confirm ('Are you sure you want to delete this row information? ') "> </ASP: linkbutton>
</Itemtemplate>
</ASP: templatefield> |
|
When you click Delete, "Are you sure you want to delete it?" is displayed on the client first ?" Dialog Box. Generally, confirm the deletion.