在会话状态下为购物车存储数据 [英] Storing Data in Session State for a Shopping Cart

查看:56
本文介绍了在会话状态下为购物车存储数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将我存储的内容添加到购物车中的会话
中,然后将其转移到另一个页面,以获取GridView来显示我添加到购物车会话中的所有项目。将其存储为对象会话。
-AddToCart获取该行的详细信息并存储在会话中,然后获取该会话对象,并将其显示在另一页的网格视图中。

trying to take what I have stored adding something to a cart into a session then transferring it to another page to get a GridView to show up of all the items that I have added onto the Cart session. Storing it as an Object Session. -AddToCart takes that rows details and stores in A Session then takes that session object and displays it on a Grid view on another page.

从它:

 protected void GridViewDisplay_RowCommand(object sender,
 GridViewCommandEventArgs e)
 {
 if (e.CommandName == "AddToCart")
 {
 object[] values;
        DataTable orderTable;
        // Retrieve the row index stored in the 
        // CommandArgument property.
        int index = Convert.ToInt32(e.CommandArgument);

        // Retrieve the row that contains the button 
        // from the Rows collection.
        GridViewRow row = GridViewDisplay.Rows[index];
        values = new Object[GridViewDisplay.Rows[0].Cells.Count];
        for (int i = 0; i < GridViewDisplay.Rows[0].Cells.Count; i++)
        {
            values[i] = GridViewDisplay.Rows[0].Cells[i].Text;
        }

       orderTable = (DataTable)Session["OrderLine"];
       orderTable.Rows.Add(values);
       Session["OrderLine"] = orderTable;


    }

}

然后现在我尝试将其存储在会话中,以便可以在另一页的网格视图中显示它。

Then Now I am trying to take that and store it in a Session so I can display it on a grid view on another page.

推荐答案

更正了代码中的问题。

protected void GridViewDisplay_RowCommand(object sender,
 GridViewCommandEventArgs e)
 {
 if (e.CommandName == "AddToCart")
 {
 object[] values;
        DataTable orderTable;
        // Retrieve the row index stored in the 
        // CommandArgument property.
        int index = Convert.ToInt32(e.CommandArgument);

        // Retrieve the row that contains the button 
        // from the Rows collection.
        GridViewRow row = GridViewDisplay.Rows[index];
        values = new Object[GridViewDisplay.Rows[0].Cells.Count];
        for (int i = 0; i < GridViewDisplay.Rows[0].Cells.Count; i++)
        {
            values[i] = row.Cells[i].Text;
        }

       orderTable = (DataTable)Session["OrderLine"];
       orderTable.Rows.Add(values);
       Session["OrderLine"] = orderTable;


    }

}

这篇关于在会话状态下为购物车存储数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆