how to delete a a prticular row in datagrid using asp.net
how to delete a a prticular row in datagrid using asp.net .please the code to delte the row in data grid .
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Lakshmanan Sethu SankaranarayanPosted Jun 16, 2014, 1:04 AM
Please Post your data grid code here.
selvi subramanianPosted Jun 16, 2014, 12:38 AM
Abhay ShankerPosted Jun 14, 2014, 2:22 PM
http://csharpexample.com/CsharpExampleSeeDetail.aspx?Did=10&CatID=21
http://www.dotnetgallery.com/kb/resource10-How-to-perform-insert-update-delete-and-select-rows-in-ASPNET-gridview-c.aspx
Satyapriya NayakPosted Jun 14, 2014, 9:24 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand();
SqlConnection con;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
con = new SqlConnection(connStr);
cmd.Connection = con;
cmd.CommandText = "Select * from student";
con.Open();
GridView1.DataSource = cmd.ExecuteReader();
GridView1.DataBind();
con.Close();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete this record:: " + DataBinder.Eval(e.Row.DataItem, "sid") + "')");
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sid = (string)GridView1.DataKeys[e.RowIndex].Value;
SqlConnection con = new SqlConnection(connStr);
cmd.Connection = con;
cmd.CommandText = "DELETE FROM student WHERE sid='" + sid + "'";
con.Open();
cmd.ExecuteNonQuery();
con.Close();
BindGrid();
}
}
selvi subramanianPosted Jun 14, 2014, 7:07 AM
Lakshmanan Sethu SankaranarayanPosted Jun 14, 2014, 6:55 AM
Pls refer this
http://www.aspsnippets.com/Articles/ASPNet-GridView---Delete-Row-with-Confirmation.aspx