Click here to Skip to main content
11,629,614 members (77,888 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MySQL
how to delete row delete in grid view (asp.net) backend my sql
Posted 23-Jan-13 23:08pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

protected void lnkdelete_Click(object sender, EventArgs e)
{
 
LinkButton lnkbtn= sender as LinkButton;
//getting particular row linkbutton
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
//getting userid of particular row
int userid = Convert.ToInt32(gvrecords.DataKeys[gvrow.RowIndex].Value.ToString());
string username = gvrow.Cells[0].Text;
con.Open();
SqlCommand cmd = new SqlCommand("delete from UserDetails where UserId="+userid,con);
int result=cmd.ExecuteNonQuery();
con.Close();
if (result == 1)
{
BindUserDetails();
//Displaying alert message after successfully deletion of user
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + username + " details deleted successfully')", true);
}

courtsy:
http://www.aspdotnet-suresh.com/2011/01/how-to-delete-records-in-gridview-with.html[^]
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


Advertise | Privacy | Mobile
Web01 | 2.8.150723.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100