Learn GridView - Part IV (Deleting Mode)

hi, now we are going to learn how we delete data from gridview


protected void GridView1_RowDeleting(Object sender, GridViewDeleteEventArgs e)
{
int id = (int)GridView1.DataKeys[e.RowIndex].Value;

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand command = new SqlCommand("delete from sqltest where CustId='"+id+"'",con);
command.Connection.Open();
command.ExecuteNonQuery();
command.Connection.Close();

GridView1.EditIndex = -1;
BindData();
}

0 comments: