Method 1: Protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e) { If (e. Row. RowType = DataControlRowType. DataRow) { E. Row. Cells [5]. Attributes. Add ("onclick", "return confirm ('' are you sure you want to edit? '')"); } } Method 2 In the GridView provided by VS2005, we can directly add a CommandField to delete the column: <asp: CommandField ShowDeleteButton = "True"/>, and then delete it in the OnRowDeleting event of the GridView. However, in general, you need to confirm the deletion before deleting the record to avoid accidental deletion. Then we can add a confirmation dialog box before deleting the GridView through the following method. First, click "Columns" in the "properties" box of the GridView to enter its "field" designer; or click the small arrow in the upper-right corner of the GridView control in the design window, click "Edit column" to enter the "field" designer. In the "field" designer's lower left "selected field" box, select the previously added CommandField "delete" column, at this time, under its attribute list on the right, you will see an item "convert this segment to TemplateFied", and click to convert it to the TemplateFied column. Then exit the "field" designer and switch to the source code view. You will find that the column has been changed from the original one: <Asp: CommandField ShowDeleteButton = "True"/> Changed: <Asp: TemplateField ShowHeader = "False"> <ItemTemplate> <Asp: LinkButton ID = "LinkButton1" runat = "server" CausesValidation = "False" CommandName = "Delete" Text = "Delete"> </asp: LinkButton> </ItemTemplate> Add OnClientClick = "return confirm ('Are you sure you want to delete this record? ');" In this way, "Are you sure you want to delete this record?" is displayed on the client first when you click Delete ?" In the dialog box, click "OK" to delete the instance. Click "cancel" to delete the instance. The Code originally written in the onRowDeleting event does not need to be changed. |