.aspx页面中
<asp:TemplateColumn>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Width="80px"></ItemStyle>
<HeaderTemplate>
<asp:Literal id="Literal3" Runat="server" Text="支付金额"></asp:Literal>
</HeaderTemplate>
<ItemTemplate>
<asp:Literal id=Literal4 Runat="server" Text='<%#PayReal((string)DataBinder.Eval(Container,"DataItem.PayWayCash").ToString(),(string)DataBinder.Eval(Container,"DataItem.PayWayCheck").ToString())%>'>
</asp:Literal>
</ItemTemplate>
</asp:TemplateColumn>
.cs页面中
AlreadyPays_ItemDataBound中
double totals=0;
for(int i=0;i<AlreadyPays.Items.Count;i++)
{
Response.Write("<script>window.alert('"+e.Item.Cells[7].Text.ToString()+"');</script>");
totals+=Convert.ToDouble(AlreadyPays.Items[i].Cells[7].Text.ToString());
}
AlreadyPays.Columns[0].FooterText="合计:";
AlreadyPays.Columns[7].FooterText=string.Format("{0:c}",totals.ToString());
可是一运行,总是提示出错
输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.FormatException: 输入字符串的格式不正确。
源错误:
行 223: {
行 224:行 225:出错
totals+=Convert.ToDouble(AlreadyPays.Items[i].Cells[7].Text.ToString());
弄了好几天了,老出问题
<asp:TemplateColumn>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle Width="80px"></ItemStyle>
<HeaderTemplate>
<asp:Literal id="Literal3" Runat="server" Text="支付金额"></asp:Literal>
</HeaderTemplate>
<ItemTemplate>
<asp:Literal id=Literal4 Runat="server" Text='<%#PayReal((string)DataBinder.Eval(Container,"DataItem.PayWayCash").ToString(),(string)DataBinder.Eval(Container,"DataItem.PayWayCheck").ToString())%>'>
</asp:Literal>
</ItemTemplate>
</asp:TemplateColumn>
.cs页面中
AlreadyPays_ItemDataBound中
double totals=0;
for(int i=0;i<AlreadyPays.Items.Count;i++)
{
Response.Write("<script>window.alert('"+e.Item.Cells[7].Text.ToString()+"');</script>");
totals+=Convert.ToDouble(AlreadyPays.Items[i].Cells[7].Text.ToString());
}
AlreadyPays.Columns[0].FooterText="合计:";
AlreadyPays.Columns[7].FooterText=string.Format("{0:c}",totals.ToString());
可是一运行,总是提示出错
输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.FormatException: 输入字符串的格式不正确。
源错误:
行 223: {
行 224:行 225:出错
totals+=Convert.ToDouble(AlreadyPays.Items[i].Cells[7].Text.ToString());
弄了好几天了,老出问题
解决方案 »
- 这个效果怎么做出来的。
- 今天初次接触三层架构的Web程序,谁能推荐一下相关书籍
- C#中正则表达式要调用函数对已匹配的数值进行处理如何办?
- 有一点错误,都打不开vs2005的设计界面,有什么办法设置一下,可以打开设计界面?
- ■■100W条记录的产品数据库应该做数据库索引来加快速度呢?
- 给框架页传值的问题
- 怎样能使dropdownlist下拉的Items的滚动条变宽????
- 网上居然找不到 asp.net 2.0 的电子书(中文PDF的)
- 各位GGJJDDMM们!!!小弟问一个简单问题!在线等,搞定结,谢谢.
- 有谁知道 Trace.Write,是做什么用的?
- 【100分】哭求IIS配置问题,解决马上给分
- DataRow 取数据的简单问题,马上就结帐
比如:AlreadyPays.Columns[7].FooterText
我看你用了合计,如果有字符串那肯定不能计算,理清思路。
问题出在这里 格式化代码{0:c}不对
问题出在这里 格式化代码{0:c}不对
——————————————————————
不对呀,结果还是0
关于ItemDataBound事件,由于这个事件是在每一个Item绑定时触发,也就是在第一行触发该事件时第二行还没有绑定数据,所以出错,e.Item是当前正在绑定的行,所以没问题;解决: 1)不要用ItemDataBound事件了,把你循环的代码跟在AlreadyPays.DataBind();后面就可以了
2)
double totals=0;
AlreadyPays_ItemDataBound(....)
{
if(e.Item.ItemIndex>-1)
{
totals+=Convert.ToDouble(AlreadyPays.Items[i].Cells[7].Text.Trim().Replace(" ","0")); }
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[0].Text ="total";
e.Item.Cells[7].Text = totals.ToString("#0.00");
}
}