.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

gridview Delete confirm box in codebehind using ASP.NET

Posted By:Athira Sreejith       Posted Date: February 22, 2009    Points: 5    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

gridview Delete confirm box in codebehind using ASP.NET.

In Row_Created Event of grid view write this line of code

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)


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


LinkButton tmpBtn = (LinkButton)e.Row.Cells[e.Row.Cells.Count - 1].Controls[e.Row.Cells[e.Row.Cells.Count - 1].Controls.Count - 1];

if (tmpBtn != null && tmpBtn.Text != "Cancel")

tmpBtn.Attributes.Add("onclick", "javascript:if (!confirm('Are you sure you want to delete this event?')) return false;");



protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)


Response.Redirect("editevent.aspx?eventid=" + GridView1.DataKeys[e.NewEditIndex].Value);


protected string GetDate(object date)


if (date != DBNull.Value && date.ToString() != "")


return DateTime.Parse(date.ToString()).ToString("dd-MMM-yyyy");



return "";




Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend