I have setup a RadGrid column to use Aggregate="sum", everything works fine... until there is no data to show, in which case I get the error "Object reference not set to an instance of an object.".
The RadGrid connects to a ObjectDataSource inline, the ObjectDataSource connects to a BLL function that returns a DataTable, when DataTable is null (no records founded), then I get the error. I guess I can go around this problem by setting the Aggregate="sum" in code behind in a proper event only when there is data, but... should not the RadGrid cover this case? If some one knows how please help!. Thanks. Below the code (the column TotalAmount contains the aggregate).
The RadGrid connects to a ObjectDataSource inline, the ObjectDataSource connects to a BLL function that returns a DataTable, when DataTable is null (no records founded), then I get the error. I guess I can go around this problem by setting the Aggregate="sum" in code behind in a proper event only when there is data, but... should not the RadGrid cover this case? If some one knows how please help!. Thanks. Below the code (the column TotalAmount contains the aggregate).
<telerik:RadGrid ID="grdOrder" runat="server" DataSourceID="ObjectDataSource1" Skin="Web20" |
AllowPaging="True" AllowSorting="false" ShowFooter="true" |
GridLines="None" AutoGenerateColumns="False"> |
<MasterTableView DataSourceID="ObjectDataSource1"> |
<NoRecordsTemplate> |
No orders to display |
</NoRecordsTemplate> |
<Columns> |
<telerik:GridBoundColumn DataField="CustomerID" HeaderText="Customer"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="CustomerName" HeaderText=""> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="OrderID" HeaderText="Order No"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="TotalAmount" HeaderText="Total" |
DataFormatString="{0:N}" Aggregate="Sum"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="CurrencyID" HeaderText="CY"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="DateCreated" HeaderText="Order Date" |
DataFormatString="{0:d}"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="DatePaid" HeaderText="Date Paid" |
DataFormatString="{0:d}"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="DateShipped" HeaderText="Date Shipped" |
DataFormatString="{0:d}"> |
</telerik:GridBoundColumn> |
<telerik:GridHyperLinkColumn DataNavigateUrlFields="OrderID" |
DataNavigateUrlFormatString="Order.aspx?orderID={0}" Text="Details..."> |
</telerik:GridHyperLinkColumn> |
</Columns> |
</MasterTableView> |
<PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" /> |
</telerik:RadGrid> |
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" |
SelectMethod="ShippedOrders" |
TypeName="Cloud1.Reports.Orders"> |
<SelectParameters> |
<asp:Parameter Name="customerID" Type="Int32" DefaultValue="0" /> |
<asp:ControlParameter ControlID="dtmFromDateCreated" Name="fromDateCreated" |
PropertyName="SelectedDate" Type="String" /> |
<asp:ControlParameter ControlID="dtmToDateCreated" Name="toDateCreated" |
PropertyName="SelectedDate" Type="String" /> |
<asp:ControlParameter ControlID="dtmFromDateShipped" Name="fromDateShipped" |
PropertyName="SelectedDate" Type="String" /> |
<asp:ControlParameter ControlID="dtmToDateShipped" Name="toDateShipped" |
PropertyName="SelectedDate" Type="String" /> |
</SelectParameters> |
</asp:ObjectDataSource> |