尝试将我存储的内容添加到购物车中以进入会话
然后将其转移到另一个页面以获取 GridView 以显示我已添加到购物车会话中的所有项目。将其存储为对象会话。
-AddToCart 获取该行详细信息并存储在会话中,然后获取该会话对象并将其显示在另一个页面的网格视图上。
从中获取以下代码:
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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)