C# 以会话状态存储购物车的数据
尝试将我存储的内容添加到购物车中,并将其添加到会话中 然后将其转移到另一个页面,以获得一个GridView,显示我添加到购物车会话中的所有项目。将其存储为对象会话。 -AddToCart获取该行的详细信息并存储在会话中,然后获取该会话对象并将其显示在另一页的网格视图中 从中获取以下代码:C# 以会话状态存储购物车的数据,c#,asp.net,entity-framework,code-first,shopping-cart,C#,Asp.net,Entity Framework,Code First,Shopping Cart,尝试将我存储的内容添加到购物车中,并将其添加到会话中 然后将其转移到另一个页面,以获得一个GridView,显示我添加到购物车会话中的所有项目。将其存储为对象会话。 -AddToCart获取该行的详细信息并存储在会话中,然后获取该会话对象并将其显示在另一页的网格视图中 从中获取以下代码: protected void GridViewDisplay_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandN
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;
}
}
现在,我尝试将其存储在会话中,以便在另一页的网格视图中显示。纠正了代码中的问题
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;
}
}
你有什么问题?什么不起作用?我编辑了你的标题。请看,如果共识是否定的,他们就不应该。顺便问一下,你有没有看过页面右侧相关部分中的任何问题?