日期:2014-05-19  浏览次数:20588 次

我是初学者,想问个问题,希望好心人能帮帮我,谢谢
在数据库表里有几个字段,goodsname,price,quantity和totalprice,我用的是access2003,把它们都设置成了文本类型,我用GridView绑定了这几列,初始值比如是:
衣服             100           1             100
鞋子             200           1             200
在下面放一个按钮实现数量的更新,我想实现点击按钮后(数量的更新已实现),但是怎么同时让totalprice的值等于price和quantity的乘积,比如:
衣服             100           2             200
鞋子             200           4             800
数量的更新我是这么实现的
  OleDbConnection   conn   =   new   OleDbConnection(@ "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source=e:\myweb\db1.mdb ");

                foreach   (GridViewRow   row   in   GridView1.Rows)
                {

                        TextBox   tb   =   (TextBox)row.Cells[2].FindControl( "TextBox2 ");
                      string   sql   =   "update   trolley   set   quantity= ' "   +   tb.Text   +   " '   where   username= ' "   +   Session[ "username "].ToString()   +   " 'and   goodsname= ' "   +   row.Cells[0].Text   +   " ' ";
                                OleDbCommand   cmd   =   new   OleDbCommand(sql,   conn);
                                  conn.Open();
                                cmd.ExecuteNonQuery();
                                conn.Close();
                                DataBind();
                }
怎么让totalprice同时也改变呢?我只有20分了,还是希望有人能帮帮我,谢谢                                
                       
 



------解决方案--------------------
TextBox tb = (TextBox)row.Cells[2].FindControl( "TextBox2 ");
TextBox tb2 = (TextBox)row.Cells[X].FindControl( "pricetextbox id ");

string sql = "update trolley set quantity= ' " + tb.Text + " ' totalprice= ' "+Convert .ToInt32(tb2.Text)*Convert .ToInt32 (tb.Text) " ' where username= ' " + Session[ "username "].ToString() + " 'and goodsname= ' " + row.Cells[0].Text + " ' ";

------解决方案--------------------
偶是个笨人,不知道有什么好的方法,可以这么做,在前面绑定的时候
<%#(double)Eval( "price ")*(double)Eval( "quantity ")%> 达到价格总和,不知道有没有更好的方法!
关注