DATALIST中有三列,前两列为代码为 <%#Eval("shuliang")%>和 <%#Eval("Price")%> 第三列为 <td align="center">价格: <asp:Label ID="sum" runat= "server" Text=' <%#Convert.ToInt32(Eval("shuliang"))*Convert.ToInt32(Eval("Price"))%>'> </asp:Label> </td> 如有3行数据的为
2 50 价格:100
3 30 价格:90
4 20 价格:80
在DATALIST外部有一个LABLE , 现在想的是如何获取 价格的总合就是500+600+700=1800用这种方法 public void bind()
{
SqlConnection con = new SqlConnection("server=.\\sqlexpress;database=dss;uid=sa;pwd=1234");
SqlDataAdapter da = new SqlDataAdapter("select * from table1", con);
DataSet ds = new DataSet();
da.Fill(ds);
ds.Tables[0].Columns.Add("PriceSum", typeof(System.String));
for(int i =0;i <ds.Tables[0].Rows.Count;i++)
{
ds.Tables[0].Rows[i]["PriceSum"]= int.Parse(ds.Tables[0].Rows[i]["quan"].ToString()) * int.Parse(ds.Tables[0].Rows[i]["Price"].ToString());
}
this.rptShoppingCart.DataSource = ds;
this.rptShoppingCart.DataBind();
}把bind()放到!ISPOSTBACK中
页面绑定 <asp:label id="sum"runat="server" text='Eval("PriceSum")'%>运行后<asp:label id="sum"runat="server" text='Eval("PriceSum")'%>不显示有编辑项摸板,点击修改保存后只显示label只显示一列quan*prcie的和而不是所有的
2 50 价格:100
3 30 价格:90
4 20 价格:80
在DATALIST外部有一个LABLE , 现在想的是如何获取 价格的总合就是500+600+700=1800用这种方法 public void bind()
{
SqlConnection con = new SqlConnection("server=.\\sqlexpress;database=dss;uid=sa;pwd=1234");
SqlDataAdapter da = new SqlDataAdapter("select * from table1", con);
DataSet ds = new DataSet();
da.Fill(ds);
ds.Tables[0].Columns.Add("PriceSum", typeof(System.String));
for(int i =0;i <ds.Tables[0].Rows.Count;i++)
{
ds.Tables[0].Rows[i]["PriceSum"]= int.Parse(ds.Tables[0].Rows[i]["quan"].ToString()) * int.Parse(ds.Tables[0].Rows[i]["Price"].ToString());
}
this.rptShoppingCart.DataSource = ds;
this.rptShoppingCart.DataBind();
}把bind()放到!ISPOSTBACK中
页面绑定 <asp:label id="sum"runat="server" text='Eval("PriceSum")'%>运行后<asp:label id="sum"runat="server" text='Eval("PriceSum")'%>不显示有编辑项摸板,点击修改保存后只显示label只显示一列quan*prcie的和而不是所有的
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货