简体   繁体   中英

how to remove row from datagrid control in asp.net using c#?

I have created a datagrid in asp.net and it loads the data.I need to remove the data on

OnItemCommand event.

So anybody knows this,help me.

you can see this Link

http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html

 protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     int userid =Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["UserId"].ToString());
     string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
     con.Open();
     SqlCommand cmd = new SqlCommand("delete from Employee_Details where UserId=" +userid, con);
     int result = cmd.ExecuteNonQuery();
     con.Close();
     if (result == 1)
     {
    BindEmployeeDetails();
    lblresult.ForeColor = Color.Red;
    lblresult.Text = username + " details deleted successfully";
     }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM