Question about the link and delete click prompt of the Gridview

Source: Internet
Author: User

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? ')");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.