Confirmation action before GridView deletion in asp.net

Source: Internet
Author: User

1. Add GridView to the page, modify the control name Gvuser

2. Set Data source DataSource (ObjectDataSource, etc.)

3. Set the DataKeyNames property of the GridView, delete operation is to follow this primary key to delete

4. Modify the code of the GridView, add modify to the inside, delete the button

<asp:gridview id= "Gvuser" runat= "Server"
autogeneratecolumns= "False" datakeynames= "UserId"
Datasourceid= "Objectdatasourceuser" 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= "Operation"/>
<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>
<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.