如何在asp.net中的网格视图的每一行中为购物车添加按钮。按钮应该删除该行

时间:2018-01-16 11:17:20

标签: c# asp.net

public void viewitemincart()
    {
        decimal total = 0;
        int rowIndex = 0;
        if (Session["Cart"] != null)
        {
            List<OrderDetail> otherorders = (List<OrderDetail>)Session["Cart"];
            DataSet ds = new DataSet();           
            foreach (OrderDetail order in otherorders)
            {
                using (SqlConnection connection = new SqlConnection(DatabaseConnection.GetConnectionString()))
                {
                    connection.Open();
                    string sql = "select "+ rowIndex+1 + " as no,itemName as Item, " + order.Quantity + " as Quantity, Price, " + order.Quantity + "*price as Total from tbl_item where itemId=" + order.ProductId;
                    SqlCommand sqlcmd = new SqlCommand(sql, connection);

                    SqlDataAdapter da = new SqlDataAdapter(sql, connection);
                    da.Fill(ds);
                    total += Convert.ToDecimal(ds.Tables[0].Rows[rowIndex]["Total"]);
                    rowIndex += 1;

                    GridView1.AutoGenerateColumns = true;                      
                    GridView1.DataSource = ds;
                    GridView1.DataBind();                     

                }
            }

            lblGrand.Visible = true;
            lblGrandTotal.Visible = true;
            lblGrandTotal.Text = total.ToString();
        }

    }
//The code binds data in session["cart"] to Grid View.
//The code is used to add item in cart session and have it displayed in grid view.
//Now, i want to add a delete button on each row of the session and upon clicking the delete button the respective row needs to be deleted from the session.

0 个答案:

没有答案