高手一看就能解决的购物车问题,我不知哪儿出错了.
这是实现商品数量修改的代码,不知哪儿有问题,总取不出 TextBox 中输入的值:
protected void btnUpdateCart_Click(object sender, EventArgs e)
{
DataTable dtb = (DataTable)Session[ "myCar "];
foreach (GridViewRow grw in this.GridView2.Rows)
{
int i = grw.RowIndex;
int theCount = Convert.ToInt32(((TextBox)this.GridView2.Rows[i].Cells[4].FindControl( "txtCount ")).Text.ToString());
DataRow UpdateDR;
UpdateDR = dtb.Rows[i];
Decimal thePrice = Convert.ToDecimal(dtb.Rows[i][ "thePrice "]);
UpdateDR[ "TheCount "] = theCount;
//oldDR[ "thePrice "] = thePrice;
UpdateDR[ "TotalPrice "] = thePrice * theCount;
Session[ "myCar "] = dtb;
Context.Server.Transfer(Request.CurrentExecutionFilePath);
}
}
以下是: aspx 页面代码:
<asp:GridView ID= "GridView2 " runat= "server " AutoGenerateColumns= "False " Height= "205px "
Width= "540px ">
<Columns>
<asp:BoundField DataField= "Id " HeaderText= "序号 " />
<asp:BoundField DataField= "goodsId " HeaderText= "商品ID " />
<asp:BoundField DataField= "thtGoodsName " HeaderText= "商品名称 " />
<asp:BoundField DataField= "thePrice " HeaderText= "单价 " />
<asp:TemplateField HeaderTe