使用GridView生成数据表我有一个网格视图,在网格视图中,我有一个按钮,当按钮被选中时,我需要在数据表中插入/更新记录.如果数据表中有值,则qty字段自增1。在数据表中插入数量为1的新行。现在问题出在我正在编写这段代码的GridView1_RowCommand上。但它在数据表中给出了错误的值。我的代码写在下面。请帮我。protectedvoidGridView1_RowCommand(objectsender,GridViewCommandEventArgse){if(e.CommandName=="datacommand"){DataTabledt=newDataTable();if(Session["product_id"]!=null){dt=(DataTable)Session["product_id"];}数据行博士;//dt.Rows[0]["数量"]=数据;如果(dt.Rows.Count<=0){dt.Columns.Add("product_id",typeof(Int32));dt.Columns.Add("数量",typeof(int));dt.Columns.Add("价格",typeof(double));dt.Columns.Add("总计",typeof(double));dr=dt.NewRow();dr["product_id"]=e.CommandArgument;博士[“数量”]=1;dr["价格"]=Convert.ToDouble(GridView1.Rows[0].Cells[3].Text);dr["总计"]=Convert.ToInt32(dr["qty"])*Convert.ToDouble(dr["价格"]);dt.Rows.Add(博士);dt.AcceptChanges();会话["product_id"]=dt;Response.Write("一次");}else{//dt=Session["product_id"];for(inti=0;i
