Friday 31 January 2014

Delete Button Inside GridView

protected void lnkdelete_Click(object sender, EventArgs e)
{

cmd.Connection = con;
con.Open();
LinkButton lnkbtn = sender as LinkButton;
//getting particular row linkbutton
GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
//getting userid of particular row
int id = Convert.ToInt32(g2.DataKeys[gvrow.RowIndex].Value.ToString());
string username = gvrow.Cells[0].Text;


cmd.CommandText = "delete details where id=@id";
cmd.Parameters.AddWithValue("@id", id);
int result = cmd.ExecuteNonQuery();
con.Close();
Response.Write(id);
gridbindedit();
}

No comments: