deleting a row of gridview and the id of product from a list
-
i have a list that I bind it to gridview.in this list I store id of products.my list is in a session..in itemtemplate column of this gridview I put a button , named delete , for deleting every row.i dont bind this gridview to sqldatasource .it binds to a list.the id of product is one of the columns of gridview.I want to when user click this button the id of that product remove from the list .how should I remove thi sid from my list and where should I write code.please help me.here is gridviewsource:
-
i have a list that I bind it to gridview.in this list I store id of products.my list is in a session..in itemtemplate column of this gridview I put a button , named delete , for deleting every row.i dont bind this gridview to sqldatasource .it binds to a list.the id of product is one of the columns of gridview.I want to when user click this button the id of that product remove from the list .how should I remove thi sid from my list and where should I write code.please help me.here is gridviewsource:
Hi, For the GridViews RowDeleting event, access the ID and remove it. Here is the steps to follow. After successful deletion re-bind the list to the GridView control. 1. For the delete button, set CommandArgument as the ID. /> 2. For the RowDeleting event. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Button btnDelete = (Button)GridView1.Rows[e.RowIndex].FindControl("btnDelete"); if (btnDelete != null) { int iProductID = Int32.Parse(btnDelete.CommandArgument); if (Session["lstProduct"] != null) { List lstProducts = (List )Session["lstProduct"]; Products oProducts = lstProducts.Find(delegate(Products p) { return p.product_id == iProductID; }); if (oProducts != null) { //Give a message : record deleted successfully. lstProducts.Remove(oProducts); Session["lstProduct"] = lstProducts; GridView1.DataSource = lstProducts; GridView1.DataBind(); } } } } Hope it helps, Thx, Gayani
-
Hi, For the GridViews RowDeleting event, access the ID and remove it. Here is the steps to follow. After successful deletion re-bind the list to the GridView control. 1. For the delete button, set CommandArgument as the ID. /> 2. For the RowDeleting event. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Button btnDelete = (Button)GridView1.Rows[e.RowIndex].FindControl("btnDelete"); if (btnDelete != null) { int iProductID = Int32.Parse(btnDelete.CommandArgument); if (Session["lstProduct"] != null) { List lstProducts = (List )Session["lstProduct"]; Products oProducts = lstProducts.Find(delegate(Products p) { return p.product_id == iProductID; }); if (oProducts != null) { //Give a message : record deleted successfully. lstProducts.Remove(oProducts); Session["lstProduct"] = lstProducts; GridView1.DataSource = lstProducts; GridView1.DataBind(); } } } } Hope it helps, Thx, Gayani
Products oProducts = lstProducts.Find(delegate(Products p)
what is delegate?I did't use product class.here is my code:
if (Session["basket"] == null)
{List pid = new List(); pid.Add(productid.Trim()); Session\["basket"\] = pid; } else { ((List)Session\["basket"\]).Add(productid.Trim()); }
Button btnDelete = (Button)GridView1.Rows[e.RowIndex].FindControl("btnDelete");
I don't have RowIndex in my smart list.
modified on Friday, September 5, 2008 3:39 PM