To delete a row with co from a grid view usnig button field?Jithil John11yAsked Mar 22, 2015, 7:46 PM EDT4 answersShareLinkedInXCopy linkSaveTo delete a row with confirmation of data from a grid view using the button field in asp.net
To delete a row with co from a grid view usnig button field?Jithil John11yAsked Mar 22, 2015, 7:46 PM EDT4 answersShareLinkedInXCopy linkSaveTo delete a row with confirmation of data from a grid view using the button field in asp.net
Keertti Raj Thangavelu BabuRank #3,979 · 374 reputation11y agoPosted Mar 22, 2015, 8:54 PM EDT0Hi Jithil,use this code:.aspx code: onrowdeleting="GridView1_RowDeleting"> .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(); if (Check != 0) { Response.Write(""); } else Response.Write(""); gvbind(); } 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(); } }0Jithil JohnRank #2,791 · 506 reputation11y agoPosted Mar 22, 2015, 9:51 PM EDT0Thanks Keertti, But i need confirmation before deletion.0Keertti Raj Thangavelu BabuRank #3,979 · 374 reputation11y agoPosted Mar 22, 2015, 10:46 PM EDT0Hi,Here is code with confirmation..cs codepublic 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 onrowdatabound="OnRowDataBound" onrowdeleting="GridView1_RowDeleting"> code--------------------------------------------------------------------------If this answer helps you. Please validate as "Accept answer".0GSg s102 reputation11y agoPosted Apr 7, 2015, 7:07 AM EDT0Button click Before checkhttp://dotnetdrizzles.blogspot.in/2015/03/confirm-message-box-with-ok-or-cancel.htmlhttp://screenshotdrizzles.blogspot.in/2015/03/confirm-message-box-with-ok-or-cancel.htmlDelete gridview Data http://dotnetdrizzles.blogspot.in/2014/09/insertupdatedelete-in-gridview-using.htmlhttp://screenshotdrizzles.blogspot.in/2014/10/insertupdatedelete-in-gridview-using.html0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jithil JohnRank #2,791 · 506 reputation11y agoPosted Mar 22, 2015, 9:51 PM EDT0Thanks Keertti, But i need confirmation before deletion.0
Keertti Raj Thangavelu BabuRank #3,979 · 374 reputation11y agoPosted Mar 22, 2015, 10:46 PM EDT0Hi,Here is code with confirmation..cs codepublic 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 onrowdatabound="OnRowDataBound" onrowdeleting="GridView1_RowDeleting"> code--------------------------------------------------------------------------If this answer helps you. Please validate as "Accept answer".0
GSg s102 reputation11y agoPosted Apr 7, 2015, 7:07 AM EDT0Button click Before checkhttp://dotnetdrizzles.blogspot.in/2015/03/confirm-message-box-with-ok-or-cancel.htmlhttp://screenshotdrizzles.blogspot.in/2015/03/confirm-message-box-with-ok-or-cancel.htmlDelete gridview Data http://dotnetdrizzles.blogspot.in/2014/09/insertupdatedelete-in-gridview-using.htmlhttp://screenshotdrizzles.blogspot.in/2014/10/insertupdatedelete-in-gridview-using.html0
Keertti Raj Thangavelu BabuRank #3,979 · 374 reputationPosted Mar 22, 2015, 8:54 PM EDT
use this code:
.aspx code:
.cs code:
Jithil JohnRank #2,791 · 506 reputationPosted Mar 22, 2015, 9:51 PM EDT
Keertti Raj Thangavelu BabuRank #3,979 · 374 reputationPosted Mar 22, 2015, 10:46 PM EDT
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".
g s102 reputationPosted Apr 7, 2015, 7:07 AM EDT
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
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts