Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to delete row delete in grid view (asp.net) backend my sql
Posted

1 solution

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[^]
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900