Asp.net VB.NET GridView忽略页脚合计中的空值
VB.net HTML: 我希望能够对这些值求和:Asp.net VB.NET GridView忽略页脚合计中的空值,asp.net,vb.net,dataview,Asp.net,Vb.net,Dataview,VB.net HTML: 我希望能够对这些值求和: Month Value Jan NULL Feb NULL Mar 15.00 Apr 10.00 但是,我发现错误无法将对象从DBNull强制转换为其他类型。 有没有办法在页脚中添加总计而忽略空值?试试这个 Month Value Jan NULL Feb NULL Mar 15.00 Apr 10.00 Total 2
Month Value
Jan NULL
Feb NULL
Mar 15.00
Apr 10.00
但是,我发现错误无法将对象从DBNull强制转换为其他类型。
有没有办法在页脚中添加总计而忽略空值?试试这个
Month Value
Jan NULL
Feb NULL
Mar 15.00
Apr 10.00
Total 25.00
编辑
首先,应该始终使用而不是Convert.ToDecimal()
感谢您的帮助,但我发现错误
输入字符串的格式不正确代码>引用Dim rowtoal As Decimal=Convert.ToDecimal(DataBinder.Eval(例如Row.DataItem,“webShopTotal”)。ToString
使用Decimal.TryParse(value,out number)而不是Convert.ToDecimal
Month Value
Jan NULL
Feb NULL
Mar 15.00
Apr 10.00
Month Value
Jan NULL
Feb NULL
Mar 15.00
Apr 10.00
Total 25.00
Protected Sub monthlyReportsUK_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If DataBinder.Eval(e.Row.DataItem, "webShopTotal").ToString IsNot Nothing AndAlso DataBinder.Eval(e.Row.DataItem, "webShopTotal").ToString IsNot DbNull.Value Then
Dim rowTotal As Decimal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "webShopTotal").ToString)
grdTotal = grdTotal + rowTotal
End Id
End If
If e.Row.RowType = DataControlRowType.Footer Then
Dim lbl As Label = DirectCast(e.Row.FindControl("lblwebsVal"), Label)
lbl.Text = "£" + grdTotal.ToString("##,0.00")
End If
End Sub
Dim result = 0
Dim rowTotal As Decimal = Decimal.TryParse(DataBinder.Eval(e.Row.DataItem, "webShopTotal").ToString), out result)