【发布时间】:2016-04-21 13:22:58
【问题描述】:
我正在尝试将网格视图数据传输到数据表中。然后将此数据表保存到会话中。为什么在此表单中显示输出
在另一个页面中设置 gridview 数据源
GridView1.DataSource = (DataTable)Session["cart"];
GridView1.DataBind();
输出
Pro Name Unit Price Quantity Total Amount
System.Web.UI.WebControls.GridViewRow
System.Web.UI.WebControls.GridViewRow
代码
foreach (GridViewRow row in GvProducts.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[0].FindControl("chkSel") as CheckBox);
if (chkRow.Checked)
{
string proid = row.Cells[1].Text;
string balance = row.Cells[3].Text;
string proname = row.Cells[2].Text;
string proqty = (row.Cells[5].FindControl("txtQuantity") as TextBox).Text;
string UnitPrice = row.Cells[6].Text;
DataTable tbl;
if (Session["cart"] == null)
{
tbl = new DataTable();
tbl.Columns.Add("Pro Name");
tbl.Columns.Add("Unit Price");
tbl.Columns.Add("Quantity");
tbl.Columns.Add("Total Amount");
}
else
tbl = (DataTable)Session["cart"];
DataRow row = tbl.NewRow();
row[0] = proname;
row[1] = Convert.ToDecimal(UnitPrice);
row[2] = proqty;
row[3] = Convert.ToInt32(proqty) * Convert.ToDecimal(UnitPrice);
tbl.Rows.Add(row);
Session["cart"] = tbl;
}
}
}
您的帮助很重要
【问题讨论】:
-
你能分享一下你面临什么样的问题...
-
如你所见,我没有得到预期的结果
标签: c# asp.net session gridview