e.Item.Cells(1).Text =ctype(myTotal,String)
解决方案 »
- ASP.NET TreeView控件使用中的问题
- 关于ASP.net+MVC+Ext js的一个问题,期待你的解答,谢谢……
- 请问如何在全局类里加上代码可以控制该网站的所有网页在同一个IP同时在一段时间内不能被刷新多少次以上
- 页面跳转无效的问题,请出现过类似情况的速来帮忙。谢谢
- 这些代码是什么意思?
- 组合控件enable=false后,状态丢失的问题,高手帮忙,在线等,多谢!!!
- 求一正则表达式~!!
- 从客户角度分析,为什么要选择asp.net而弃用asp?
- 在treeview控件中,如何获得当前节点的父节点?
- 寻求.NET高手,做师傅!!!
- 利用“IE自带的WebBrowser控件实现打印”如何在后台进行设置?
- 如何设计能同时添加多条纪录的界面,一直在线等。请大家帮忙
myTotal += Convert.ToDouble(e.Item.Cells(1).Text)
myTotal += IIF(trim(e.Item.Cells(1).Text)="",0,cdbl(e.Item.Cells(1).Text))
myTotal += cdbl(e.Item.Cells(1).Text)myTotal是Double,就报错:[InvalidCastException: 从字符串“”到类型“Double”的强制转换无效。]
我用 If Trim(e.Item.Cells(1).Text) = "" Then
e.Item.Cells(1).Text = 0
End If
那么,DataGrid 的每一行都显示0
Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String Value, NumberFormatInfo NumberFormat) +195
Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value, NumberFormatInfo NumberFormat) +84[InvalidCastException: 从字符串“”到类型“Double”的强制转换无效。]
Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value, NumberFormatInfo NumberFormat) +172
Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value) +7
WebApp.Bill_Ins.DataGrid1_ItemDataBound(Object sender, DataGridItemEventArgs e) in \\Master\d$\MyWeb\WebApp\Bill\Bill_Ins.aspx.vb:349
System.Web.UI.WebControls.DataGridItemEventHandler.Invoke(Object sender, DataGridItemEventArgs e) +0
System.Web.UI.WebControls.DataGrid.OnItemDataBound(DataGridItemEventArgs e) +110
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource) +181
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +1408
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +49
System.Web.UI.WebControls.BaseDataList.DataBind() +23
WebApp.Bill_Ins.GetData() in \\Master\d$\MyWeb\WebApp\Bill\Bill_Ins.aspx.vb:118
WebApp.Bill_Ins.Page_Load(Object sender, EventArgs e) in \\Master\d$\MyWeb\WebApp\Bill\Bill_Ins.aspx.vb:56
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
Select Case e.Item.ItemType
Case ListItemType.AlternatingItem, ListItemType.Item 'Calculate total for the field of each row and alternating row.
If e.Item.Cells(1).Text <> " " Then
myTotal(0) += CDbl(e.Item.Cells(1).Text)
End If myTotal(1) += CDbl(e.Item.Cells(2).Text)
myTotal(2) += CDbl(e.Item.Cells(3).Text)
myTotal(3) += CDbl(e.Item.Cells(4).Text)
myTotal(4) += CDbl(e.Item.Cells(5).Text) Case ListItemType.Footer
'Use the footer to display the summary row.
e.Item.Cells(0).Text = "合计:"
e.Item.Cells(1).Text = myTotal(0).ToString
e.Item.Cells(2).Text = myTotal(1).ToString
e.Item.Cells(3).Text = myTotal(2).ToString
e.Item.Cells(4).Text = myTotal(3).ToString
e.Item.Cells(5).Text = myTotal(4).ToString
'e.Item.Cells(2).Text = myTotal(0).ToString("c")
End Select
肯定是(e.Item.Cells(1).Text)里面的数据有问题!!如果是string,显示就是空白!
怀疑是空值出现这种错误
你看看里面是什么值
但是,“如果是string,显示就是空白!”--这时候atagrid显示正确;
当我用下面语句判断时,datagrid显示全部是0!
If e.Item.Cells(1).Text = "" Then
e.Item.Cells(1).Text = 0
End If
对呀 说明你从数据库中读取得数据都是空值呀!!!
cdbl(空值) 当然会出错了!!
If e.Item.Cells(1).Text = "" Then
e.Item.Cells(1).Text ="0"
End If
加上这句呀!!!
myTotal(0) += CDbl(e.Item.Cells(1).Text)
End If这句的意思是不是空格就执行!!适合我不一定适合你
If e.Item.Cells(1).Text = "" Then
e.Item.Cells(1).Text ="0"
End If
就可以了
"当我用下面语句判断时,datagrid显示全部是0!
If e.Item.Cells(1).Text = "" Then
e.Item.Cells(1).Text = 0
End If"
问题是,不加上上面的语句,datagrid显示是正确的。
====
题外话:我已经用其他办法解决了问题。但是,微软推荐的方法为什么就不行?