ВБ.нет
Protected Sub monthlyReportsUK_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim rowTotal As Decimal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "webShopTotal").ToString)
grdTotal = grdTotal + rowTotal
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
HTML:
<asp:TemplateField HeaderText="webShopTotal">
<ItemTemplate>
<asp:Label ID="lblamount" runat="Server" Text='<%# Eval("webShopTotal") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblwebsVal" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
Вид сетки
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
Однако я получаю сообщение об ошибке Object cannot be cast from DBNull to other types.
Есть ли способ добавить итог в нижний колонтитул, игнорируя значения NULL?