Sorry if this is a duplicate post. The other one did not show up in the list so I assume it got lost somehow.
telerik version: 2011.1.315.40
browser: FF
.net 4.0
VS 2010.
I have a radgrid with a nestedviewtemplate containing another radgrid. I am exporting to excel using a button in the radtoolbar control.
I am using advanced databinding for the master and child grids. The grids render the data with no errors. However, when exporting this error is raised: I have researched many posts on various binding techniques and am wondering if its related to that. I had the export working before when I used client side binding. Attached below are the aspx and .cs files. Please Help and Thanks in Advance.
ASPX:
CS codebehind:
telerik version: 2011.1.315.40
browser: FF
.net 4.0
VS 2010.
I have a radgrid with a nestedviewtemplate containing another radgrid. I am exporting to excel using a button in the radtoolbar control.
I am using advanced databinding for the master and child grids. The grids render the data with no errors. However, when exporting this error is raised: I have researched many posts on various binding techniques and am wondering if its related to that. I had the export working before when I used client side binding. Attached below are the aspx and .cs files. Please Help and Thanks in Advance.
Object reference not set to an instance of an object.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error:An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Stack Trace:[NullReferenceException: Object reference not set to an instance of an object.] Telerik.Web.UI.GridTableView.PrepareExport() +17 Telerik.Web.UI.Grid.Export.TableViewExporter.PrepareForExportInternal(GridTableView tableView, Boolean ignorePaging, Boolean dataOnly) +321 Telerik.Web.UI.GridTableView.ClearTableViewControls(Control control, TableViewExporter exporter, GridTableView ownerTable) +583 System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.UI.Control.PreRenderRecursiveInternal() +112 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4184<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"><script type="text/javascript"> var currentLoadingPanel = null; var currentUpdatedControl = null; function OnDateSelected(sender, e) { var monthPicker = $find("<%= RadMonthYearPicker.ClientID %>"); var startDatePicker = $find("<%= RadDatePickerStartDate.ClientID %>"); var endDatePicker = $find("<%= RadDatePickerEndDate.ClientID %>"); var selectedMonth = monthPicker.get_selectedDate(); //set start date default, min and max var year = selectedMonth.getFullYear(); var month = selectedMonth.getMonth(); var minDate = new Date(year, month, 1); var maxDate = new Date(year, month + 1, 0); startDatePicker.set_minDate(minDate); startDatePicker.set_maxDate(maxDate); startDatePicker.set_selectedDate(minDate); //set end date default, min and max endDatePicker.set_minDate(minDate); //need to be sure we dont go into the future endDatePicker.set_maxDate(maxDate); endDatePicker.set_selectedDate(maxDate); }</script></telerik:RadCodeBlock><div class="filter2-single-column-layout"> <div class="section"> <div class="content"> <table> <tr> <td> Custom Date Range: </td> <td> <asp:CheckBox ID="CheckBoxCustomDateRange" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBoxCustomDateRange_CheckedChanged"></asp:CheckBox> </td> <td> Or Select Month:</td> <td><telerik:RadMonthYearPicker ID="RadMonthYearPicker" Width="125px" runat="server" > <ClientEvents OnDateSelected="OnDateSelected"></ClientEvents> </telerik:RadMonthYearPicker></td> <td > Start: </td> <td> <telerik:RadDateTimePicker ID="RadDatePickerStartDate" Width="155px" runat="server" ShowPopupOnFocus="False"></telerik:RadDateTimePicker> </td> <td > <asp:RequiredFieldValidator ID="RequiredFieldValidatorStartDate" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="RadDatePickerStartDate"></asp:RequiredFieldValidator> </td> <td> End: </td> <td> <telerik:RadDateTimePicker ID="RadDatePickerEndDate" Width="155px" runat="server" ShowPopupOnFocus="False"></telerik:RadDateTimePicker> </td> <td> <asp:RequiredFieldValidator ID="RequiredFieldValidatorEndDate" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="RadDatePickerEndDate"></asp:RequiredFieldValidator> <asp:CompareValidator ID="CompareValidator1" ControlToValidate="RadDatePickerStartDate" Operator="LessThanEqual" ControlToCompare="RadDatePickerEndDate" runat="server" ForeColor="Red" ErrorMessage="*"></asp:CompareValidator> </td> <td> <telerik:RadToolBar runat="server" ID="RadToolBar" EnableRoundedCorners="True" OnButtonClick="RadToolBar_ButtonClick" AutoPostBack="true"> <Items > <telerik:RadToolBarButton Text="Search" ToolTip="Search (Alt+S)" CommandName="search" ></telerik:RadToolBarButton> </Items> </telerik:RadToolBar> </td> <td> <telerik:RadComboBox runat="server" ID="CustomerSelector" Width="100px"> <Items> <telerik:RadComboBoxItem Text="1001005" Value="1001005" /> </Items> </telerik:RadComboBox> </td> </tr> </table> </div> </div></div> <div class="column-full"> <telerik:RadToolBar ID="gridtemplateButtons" runat="server" EnableEmbeddedBaseStylesheet="false" EnableEmbeddedSkins="false" OnButtonClick="gridtemplateButtons_ButtonClick" AutoPostBack="true" Height="22px"><Items> <telerik:RadToolBarButton Text="Manage Cards..." ToolTip="" CommandName="ManageCards"></telerik:RadToolBarButton> <telerik:RadToolBarButton IsSeparator="true" /> <telerik:RadToolBarDropDown Text="Export" AccessKey="e" ToolTip="Export (Alt+E)"> <Buttons> <telerik:RadToolBarButton IsSeparator="true"> </telerik:RadToolBarButton> <telerik:RadToolBarButton ImageUrl="~/Images/stratos_icon_16x16_settings3.gif" ImagePosition="Left" Text="Export MS Excel" CommandName="ExportToExcel"> </telerik:RadToolBarButton> </Buttons> </telerik:RadToolBarDropDown></Items></telerik:RadToolBar><telerik:RadGrid ID="RadGridTrafficSummary" EnableViewState="true" runat="server"Visible="true" GroupingEnabled="true" AllowSorting="True" AllowPaging="True"AllowFilteringByColumn="true" AllowMultiRowSelection="False" ShowStatusBar="true" AutoGenerateColumns="False" OnNeedDataSource="RadGridTrafficSummary_NeedDataSource" OnPreRender="RadGridTrafficSummary_PreRender" ShowFooter="true"> <MasterTableView AutoGenerateColumns="False" DataKeyNames="imsi" Width="100%"><PagerStyle Mode="NextPrevNumericAndAdvanced" /><Columns> <telerik:GridBoundColumn FilterControlWidth="45px" HeaderStyle-Width="40px" ItemStyle-Width="20px" AllowFiltering="true" AllowSorting="false" HeaderTooltip="" DataType="System.String" DataField="accountnr" HeaderText="Acct #"></telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="45px" HeaderStyle-Width="50px" ItemStyle-Width="40px" HeaderTooltip="" DataType="System.String" DataField="customerId" HeaderText="Customer #"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="80px" ItemStyle-Width="80px" HeaderTooltip="" DataField="cname" DataType="System.String" HeaderText="Name"></telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="40px" HeaderStyle-Width="40px" ItemStyle-Width="40px" HeaderTooltip="" DataType="System.String" DataField="product" HeaderText="Product"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="80px" ItemStyle-Width="80px" HeaderTooltip="" DataField="imsi" DataType="System.String" HeaderText="IMSI"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="100px" ItemStyle-Width="100px" HeaderTooltip="" DataField="ICCID" DataType="System.String" HeaderText="ICCID"></telerik:GridBoundColumn> <telerik:GridNumericColumn FilterControlWidth="60px" HeaderStyle-Width="50px" ItemStyle-Width="50px" AllowFiltering="true" FooterStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" DataType="System.Decimal" HeaderStyle-HorizontalAlign="Right" HeaderTooltip="" DataField="MBsIn" HeaderText="MBs In"></telerik:GridNumericColumn > <telerik:GridNumericColumn FilterControlWidth="60px" HeaderStyle-Width="50px" ItemStyle-Width="50px" AllowFiltering="true" FooterStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" DataType="System.Decimal" HeaderStyle-HorizontalAlign="Right" HeaderTooltip="" DataField="MBsOut" HeaderText="MBs Out"></telerik:GridNumericColumn > <telerik:GridNumericColumn FilterControlWidth="60px" HeaderStyle-Width="50px" ItemStyle-Width="50px" AllowFiltering="true" FooterStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" DataType="System.Decimal" HeaderStyle-HorizontalAlign="Right" HeaderTooltip="" DataField="MBsTotal" HeaderText="MBs Total" ></telerik:GridNumericColumn > <telerik:GridBoundColumn FilterControlWidth="35px" HeaderStyle-Width="35px" ItemStyle-Width="35px" DataType="System.String" HeaderTooltip="To Unsubscribe, use the Manage Cards button." DataField="subscription" HeaderText="Subscribed"></telerik:GridBoundColumn> <telerik:GridBoundColumn visible="false" DataType="System.String" DataField="startdate"></telerik:GridBoundColumn> <telerik:GridBoundColumn visible="false" DataType="System.String" DataField="enddate"></telerik:GridBoundColumn></Columns><NestedViewTemplate> <telerik:RadGrid runat="server" ID="RadGridTrafficImsiDetails" EnableViewState="true" GroupingEnabled="true" ShowFooter="true" AllowFilteringByColumn="true" AllowSorting="true" > <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true" PageSize="7" > <PagerStyle Mode="NextPrevNumericAndAdvanced" /> <Columns> <telerik:GridBoundColumn visible="false" HeaderTooltip="" DataField="imsi" HeaderText="IMSI"></telerik:GridBoundColumn> <telerik:GridBoundColumn visible="false" HeaderTooltip="" DataField="iccid" HeaderText="ICCID"></telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="30px" HeaderStyle-Width="20px" ItemStyle-Width="20px" DataField="service" HeaderText="Service"></telerik:GridBoundColumn> <telerik:GridNumericColumn FilterControlWidth="60px" HeaderStyle-Width="40px" ItemStyle-Width="40px" AllowFiltering="true" FooterStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" DataType="System.Decimal" HeaderStyle-HorizontalAlign="Right" HeaderTooltip="" DataField="MBsIn" HeaderText="MBs In" HeaderStyle-Wrap="false"></telerik:GridNumericColumn> <telerik:GridNumericColumn FilterControlWidth="60px" HeaderStyle-Width="40px" ItemStyle-Width="40px" AllowFiltering="true" FooterStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" Aggregate="Sum" DataType="System.Decimal" HeaderStyle-HorizontalAlign="Right" HeaderTooltip="" DataField="MBsOut" HeaderText="MBs Out" HeaderStyle-Wrap="false"></telerik:GridNumericColumn> <telerik:GridBoundColumn HeaderStyle-Width="30px" ItemStyle-Width="30px" HeaderTooltip="" DataField="srcip" HeaderText="Source IP"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="30px" ItemStyle-Width="30px" HeaderTooltip="" DataField="dstip" HeaderText="Dest IP"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="60px" ItemStyle-Width="60px" HeaderTooltip="" DataField="domain" HeaderText="Domain"></telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="30px" HeaderStyle-Width="20px" ItemStyle-Width="20px" HeaderTooltip="" DataField="Port" HeaderText="Port"></telerik:GridBoundColumn> <telerik:GridDateTimeColumn FilterControlWidth="130px" HeaderStyle-Width="120px" ItemStyle-Width="120px" HeaderTooltip="" DataField="dstamp" HeaderText="Date"></telerik:GridDateTimeColumn> <telerik:GridBoundColumn FilterControlWidth="30px" HeaderStyle-Width="20px" ItemStyle-Width="20px" HeaderTooltip="" DataField="Denied" HeaderText="Denied"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="30px" ItemStyle-Width="30px" HeaderTooltip="" DataField="reason" HeaderText="Reason"></telerik:GridBoundColumn> <telerik:GridBoundColumn Visible="false" DataType="System.String" DataField="subscription"></telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid></NestedViewTemplate> </MasterTableView> </telerik:RadGrid></div>using System;using System.Data;using System.Data.SqlClient;using System.Configuration;using System.Collections.Generic;using System.Linq;using System.Web;using System.Drawing;using System.Web.UI;using System.Web.UI.WebControls;using Stratos.Libraries.Data;using Telerik.Charting;using Telerik.Web.UI;using Telerik.Web.UI.Calendar;namespace Stratos.Web.Portal.Reports{ public partial class TrafficDashboard_01_export : System.Web.UI.Page { TimeSpan allowableTimeSpan = new TimeSpan(365, 0, 0, 0); //1 full year private void SetStartEndDateRange() { this.RadMonthYearPicker.MinDate = DateTime.Now.Subtract(allowableTimeSpan); this.RadMonthYearPicker.MaxDate = DateTime.Now; this.RadMonthYearPicker.SelectedDate = DateTime.Now; //set start/end date min/max this.RadDatePickerStartDate.MinDate = DateTime.Now.Subtract(allowableTimeSpan); this.RadDatePickerStartDate.MaxDate = DateTime.Now; this.RadDatePickerEndDate.MinDate = DateTime.Now.Subtract(allowableTimeSpan); this.RadDatePickerEndDate.MaxDate = DateTime.Now; this.RadDatePickerStartDate.Clear(); this.RadDatePickerEndDate.Clear(); this.RadDatePickerStartDate.SelectedDate = new DateTime(RadMonthYearPicker.SelectedDate.Value.Year, RadMonthYearPicker.SelectedDate.Value.Month, 1); this.RadDatePickerEndDate.SelectedDate = DateTime.Now.Subtract(new TimeSpan(0, 0, 1)); } protected void Page_Init(object sender, System.EventArgs e) { if (!IsPostBack) { SetStartEndDateRange(); } } public void Page_Load(object sender, System.EventArgs e) { //if sdate edate strings are null. Load page as if we came from menu if (String.IsNullOrEmpty(Request.QueryString["StartDate"]) || String.IsNullOrEmpty(Request.QueryString["EndDate"])) { } //if sdate edate strings are not null, we came from somewhere with dates, load data with them. else { this.RadDatePickerStartDate.SelectedDate = DateTime.Parse((Request.QueryString["StartDate"].ToString())); //ToString("dd-MMM-yyyy HH:mm:ss"); this.RadDatePickerEndDate.SelectedDate = DateTime.Parse((Request.QueryString["EndDate"].ToString())); } } protected void CheckBoxCustomDateRange_CheckedChanged(object sender, System.EventArgs e) { SetStartEndDateRange(); if (CheckBoxCustomDateRange.Checked) { this.RadMonthYearPicker.Enabled = false; } else { this.RadMonthYearPicker.Enabled = true; } } protected void RadToolBar_ButtonClick(object sender, Telerik.Web.UI.RadToolBarEventArgs e) { RadToolBarButton buttons = e.Item as RadToolBarButton; if (buttons.CommandName.ToString().ToLower() == "search") { RadGridTrafficSummary.Rebind(); } } protected void gridtemplateButtons_ButtonClick(object sender, RadToolBarEventArgs e) { RadToolBarButton gridtemplateButtons = e.Item as RadToolBarButton; if (gridtemplateButtons.CommandName.ToString().ToLower() == "exporttoexcel") { ConfigureExport(RadGridTrafficSummary); RadGridTrafficSummary.MasterTableView.ExportToExcel(); } } protected void RadGridTrafficSummary_PreRender(object sender, EventArgs e) { foreach (GridDataItem gridDataItem in (sender as RadGrid).MasterTableView.Items) { if (gridDataItem.Expanded) { GridNestedViewItem gridNestedViewItem = gridDataItem.ChildItem; if (gridNestedViewItem != null) { RadGrid RadGridTrafficImsiDetails = (RadGrid)gridNestedViewItem.FindControl("RadGridTrafficImsiDetails"); RadGridTrafficImsiDetails.DataSource = NetStats.GetImsiDetailTraffic(GetScopeLimitation(), (DateTime)RadDatePickerStartDate.SelectedDate, (DateTime)RadDatePickerEndDate.SelectedDate, gridDataItem["imsi"].Text); RadGridTrafficImsiDetails.DataBind(); } } } } private void ConfigureExport(object sender) { (sender as RadGrid).ExportSettings.ExportOnlyData = true; (sender as RadGrid).ExportSettings.IgnorePaging = true; (sender as RadGrid).MasterTableView.HierarchyDefaultExpanded = true; } protected void RadGridTrafficSummary_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { RadGridTrafficSummary.DataSource = NetStats.GetCustomerTrafficSummary(GetScopeLimitation(), (DateTime)RadDatePickerStartDate.SelectedDate, (DateTime)RadDatePickerEndDate.SelectedDate); } private String GetScopeLimitation() { //TODO build the users scope limitation, a list of customer and sub customers that they can view. String scopeLimitation = " customerid in ( "; // ConfigurationManager.AppSettings["TDB_ScopeLimitation"]; scopeLimitation = scopeLimitation + "'" + GetSelectedCustomer() + "'"; scopeLimitation = scopeLimitation + GetSelectedCustomerSubCustomers(GetSelectedCustomer()) + " ) "; return scopeLimitation; } private String GetSelectedCustomer() { return CustomerSelector.SelectedValue; } private String GetSelectedCustomerSubCustomers(String customer) { if (customer == "1001005") return " , '1004515', '1004516', '1005417','1004517', '1005301', '1005578', '1005579', '1005580', '1007909', '1008578', '1010285', '1010834'"; else return ""; } }}