Confirmation before deleting the gridview in Asp.net

Source: Internet
Author: User

1. Add the gridview to the page and modify the control name gvuser.

2. Set the data source datasource (objectdatasource, etc)

3. Set the datakeynames attribute of the gridview,The delete operation is based on this primary key.

4. modify the code of the gridview and add the modify and delete buttons to it.

<Asp: gridview id = "gvuser" runat = "server"
Autogeneratecolumns = "false" datakeynames = "userid"
Performanceid = "objectperformanceuser" onrowdeleted = "gvuser_rowdeleted">
<Columns>
<Asp: boundfield datafield = "userid" headertext = "userid"
Sortexpression = "userid"/>
<Asp: boundfield datafield = "username" headertext = "username"
Sortexpression = "username"/>
<Asp: boundfield datafield = "userpass" headertext = "userpass"
Sortexpression = "userpass"/>
<Asp: boundfield datafield = "role" headertext = "role" sortexpression = "role"/>
<Asp: boundfield datafield = "regtime" headertext = "regtime"
Sortexpression = "regtime"/>
<Asp: boundfield datafield = "lognum" headertext = "lognum"
Sortexpression = "lognum"/>
<Asp: commandfield showeditbutton = "true" headertext = ""/>
<Asp: templatefield showheader = "false">
<Itemtemplate>
<Asp: linkbutton id = "lbdelete" runat = "server" causesvalidation = "false"
Onclientclick = "Return confirm ('Are you sure you want to delete it? ') "Text =" delete "commandname =" delete "> </ASP: linkbutton>
</Itemtemplate>
<Headerstyle forecolor = "# 0033cc"/>
<Itemstyle horizontalalign = "center" verticalalign = "Middle"/>
</ASP: templatefield>

</Columns>
</ASP: gridview>

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.