To delete a row with co from a grid view usnig button field?
To delete a row with confirmation of data from a grid view using the button field in asp.net
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.
g sPosted Apr 7, 2015, 11:07 AM
http://dotnetdrizzles.blogspot.in/2015/03/confirm-message-box-with-ok-or-cancel.html
http://screenshotdrizzles.blogspot.in/2015/03/confirm-message-box-with-ok-or-cancel.html
Delete gridview Data
http://dotnetdrizzles.blogspot.in/2014/09/insertupdatedelete-in-gridview-using.html
http://screenshotdrizzles.blogspot.in/2014/10/insertupdatedelete-in-gridview-using.html
Keertti Raj Thangavelu BabuPosted Mar 23, 2015, 2:46 AM
Here is code with confirmation.
.cs code
public partial class gridview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gvbind();
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection connect = new SqlConnection("Data Source=sqlserver;Initial Catalog=DB;Integrated Security=true;");
int empid = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[1].Text);
connect.Open();
SqlCommand cmd = new SqlCommand("delete FROM tabelname where columnname= @EmpID", connect);
cmd.Parameters.Add("@EmpID", SqlDbType.Int).Value = Convert.ToInt32(empid);
int Check = Convert.ToInt32(cmd.ExecuteNonQuery());
connect.Close();
gvbind();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState != DataControlRowState.Edit)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb = (LinkButton)e.Row.Cells[0].Controls[0];
if (lb != null)
{
lb.OnClientClick = "return confirm('You want to delete this data ?');";
}
}
}
}
public void gvbind()
{
SqlConnection connect = new SqlConnection("Data Source=sqlserver;Initial Catalog=DB;Integrated Security=true;");
connect.Open();
SqlCommand scom = new SqlCommand();
scom.Connection = connect;
scom.CommandText = "Select * from tabelname";
DataSet ds = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter();
dap.SelectCommand = scom;
dap.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
----------------------------------
.aspx code
code
--------------------------------------------------------------------------
If this answer helps you. Please validate as "Accept answer".
Jithil JohnPosted Mar 23, 2015, 1:51 AM
Keertti Raj Thangavelu BabuPosted Mar 23, 2015, 12:54 AM
use this code:
.aspx code:
.cs code: