For example, if the Gridview has two columns: cancel and delete, click the column and prompt for execution.
Copy codeThe Code is as follows:
<Asp: HyperLinkField DataNavigateUrlFields = "id" DataNavigateUrlFormatString = "HospitalView. aspx? Id = {0} "DataTextField =" id "DataTextFormatString =" cancel "HeaderText =" cancel "HeaderStyle-HorizontalAlign =" Center "ItemStyle-HorizontalAlign =" Center "HeaderStyle-Width =" 60 "ItemStyle-Width =" 60 "/>
<Asp: commandField ShowDeleteButton = "True" DeleteText = "delete" HeaderText = "delete" HeaderStyle-HorizontalAlign = "Center" ItemStyle-HorizontalAlign = "Center" HeaderStyle-Width = "60" ItemStyle-Width = "60"/>
If the following message is displayed in the background:
Copy codeThe Code is as follows:
E. Row. Cells [6]. Attributes. Add ("onclick", "return confirm ('Are you sure you want to cancel? ')");
E. Row. Cells [7]. Attributes. Add ("onclick", "return confirm ('Are you sure you want to delete this data? ')");
In this way, an event is bound to the cells in the Gridview. If you do not click the text, you only need to click the cell where the text is located. A prompt is displayed, Which is unfriendly.
Solution:
Copy codeThe Code is as follows:
(HyperLink) e. Row. Cells [6]. Controls [0]). Attributes. Add ("onclick", "return confirm ('Are you sure you want to cancel? ')");
(LinkButton) e. Row. Cells [7]. Controls [0]). Attributes. Add ("onclick", "return confirm ('Are you sure you want to delete this data? ')");