Delete Message of Confirmation

Vipul
Posted by in ASP.NET category on for Beginner level | Views : 5763 red flag

This is delete confirmation in Gridview
 
 
 
Introduction

This is simple to create Delete Confirmation Message.


1.Write following Code in Your WebPage for test this.

<asp:GridView

id="grdEmployees"

DataSourceId="srcEmployees"

DataKeyNames="Id"

AllowPaging="true"

AutoGenerateColumns="false"

GridLines="both"

Runat="server" OnRowCreated="grdEmployees_RowCreated">

<Columns>

<asp:CommandField ShowDeleteButton="true" />

<asp:BoundField DataField="LastName" HeaderText="Last Name" />

<asp:BoundField DataField="FirstName" HeaderText="First Name" />

</Columns>

</asp:GridView>

<asp:SqlDataSource

id="srcEmployees"

ConnectionString="Data Source=.\SQLExpress;

AttachDbFilename=|DataDirectory|Table.mdf;

Integrated Security=True;User Instance=True"

SelectCommand="SELECT * FROM Employees"

DeleteCommand="DELETE Employees WHERE Id=@Id"

Runat="server" />

 

2.Write following Code on Gridviews RowCreated Event

protected void grdEmployees_RowCreated(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

LinkButton lnkDelete = (LinkButton)e.Row.Cells[0].Controls[0];

lnkDelete.Attributes["onclick"] = "return confirm('Delete Record?')";

}

}

Page copy protected against web site content infringement by Copyscape

About the Author

Vipul
Full Name: vipul vk
Member Level: Starter
Member Status: Member
Member Since: 4/15/2009 9:08:15 PM
Country:

http://www.dotnetfunda.com
Working as a software developer

Login to vote for this post.

Comments or Responses

Posted by: Vinay13mar on: 10/14/2012 | Points: 25
this is really nice article. i have found a similar article also please check
http://dotnetpools.com/Article/ArticleDetiail/?articleId=6&title=GridView%20Delete%20With%20Confirmation%20Message

Login to post response

Comment using Facebook(Author doesn't get notification)