Net-informations.com
SiteMap  | About    

ASP.NET GridView Delete

The GridView control provides many built-in capabilities that allow the user to sort, update, delete, select, and page through items in the control. The following tutorial shows how to delete a row from Gridview and display a confirmation message before deleting the specified row.

gridview-delete

Download Database

In this article I have used Microsoft's Pubs database for sample data. You can download it free from the following link.

Download

Before you start to create Edit functionality on GridView in your asp file, you should create a ConnectionString in your web.Config File. Double click the web.config file on the right hand side of the Visual Studio and add the following connectionstring code in that file.

web.config file

Web.Config File

To enable delete , set the AutoGenerateDeleteButton to true and specify the delete command in the SqlDataSource.

  DeleteCommand="DELETE From [stores] WHERE [stor_id] = @stor_id"

Here we are trying to display a confirmation message before deleting the specified row. In order to doing this we have to write a small Javascript code for display confirmation message.

  function isDelete()
  {
	return confirm("Do you want to delete this row ?");
  }

We have to call this Javascript function on OnClientClick event of the delete LinkButton.

The follwoing ASP.NET program shows how to delete a row from Gridview and display a confirmation message before deleting the specified row.

Default.aspx


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb






net-informations.com (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.