Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. deleting a row of gridview and the id of product from a list

deleting a row of gridview and the id of product from a list

Scheduled Pinned Locked Moved ASP.NET
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    strawberrysh
    wrote on last edited by
    #1

    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:

    G 1 Reply Last reply
    0
    • S strawberrysh

      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:

      G Offline
      G Offline
      Gayani Devapriya
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • G Gayani Devapriya

        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

        S Offline
        S Offline
        strawberrysh
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups