This is a migrated thread and some comments may be shown as answers.

Export nested radgrid to excel, errors with NullReferenceException

5 Answers 376 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 03 May 2011, 08:13 PM
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.
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
ASPX:
<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>
CS codebehind:
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 "";
        }
    }
}


5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 09 May 2011, 12:18 PM
Hello Peter,

Judging by the error message (and your code), I suppose this is a databinding-issue. Instead of binding the nested RadGrid on PreRender, I suggest that you take advantage of the advanced data-binding capabilities and populate the grid in NeedDataSource event:
Advanced Data-binding (using NeedDataSource event)

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Peter
Top achievements
Rank 1
answered on 09 May 2011, 03:21 PM
Hi Daniel,
Thanks for the tip..
I have tried to do what you've said. I had to search the forms to see how to access the master grids primary id while inside the nested grids needdatasource event, so that the nested grid can be bound to the correct parent row. But this causes a null object error. Here is the code Ive used to do this, along with the error. Any advice on what Im doing wrong? (the line in BOLD is where it fails).
protected void RadGridTrafficImsiDetails_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    RadGrid nestedRadGrid = (RadGrid)source;
    GridDataItem item = (GridDataItem)(nestedRadGrid.NamingContainer as GridEditFormItem).ParentItem;  // Get the mastertableview item
    if (item != null)
    {
        string imsi = item["imsi"].Text; // Get the imsi from the master grid
        if (imsi != null && RadDatePickerStartDate.SelectedDate != null && RadDatePickerEndDate.SelectedDate != null)
        {
            // Populate the nested grid according to the master grid imsi value.
            nestedRadGrid.DataSource = NetStats.GetImsiDetailTraffic(GetScopeLimitation(), (DateTime)RadDatePickerStartDate.SelectedDate, (DateTime)RadDatePickerEndDate.SelectedDate, imsi);
        }
    }
}
And the error:
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:
 
Line 684:        {
Line 685:            RadGrid nestedRadGrid = (RadGrid)source;
Line 686:            GridDataItem item = (GridDataItem)(nestedRadGrid.NamingContainer as GridEditFormItem).ParentItem;  // Get the mastertableview item
Line 687:            if (item != null)
Line 688:            {
0
Peter
Top achievements
Rank 1
answered on 09 May 2011, 03:46 PM
Hi Again..

I got it..
just had to change one piece of the code to:
GridDataItem item = (GridDataItem)(nestedRadGrid.NamingContainer as GridNestedViewItem).ParentItem;
and then it worked..
Thanks..
0
Peter
Top achievements
Rank 1
answered on 10 May 2011, 12:48 PM
Hi again Daniel..
I have got past the null reference exception due to incorrect databinding. Thanks for the help on that.

Two follow on questions:.
Using the same code from this thread I am now able to export to excel and CSV.
BUT...
1) the csv file that gets created contains just the master grid contents, there are no nested grid contents. Any ideas on this?
2) The excel file that gets created contains the master and nested grid contents as expected BUT with a different problem, the excel file contains the grouping and filtering menus along with the data.. Even though I have exportdataonly to true on both grids. Ideas here?

Here are additional code snippets showing how I have the grids coded to enable the export: This is the grid template event handler where the export button resides. Here, I was trying to stop the grouping and filtering items from appearing in the excel file. I thought by turning off these things prior to the export would work but no, it had no affect. Also, I was reading on another thread that for export I should be rebinding the nested grid on the itemdatabound event of the master grid.. so i am showing that snippet too. Thanks in advance for your help.
protected void gridtemplateButtons_ButtonClick(object sender, RadToolBarEventArgs e)
       {
           RadToolBarButton gridtemplateButtons = e.Item as RadToolBarButton;
           if (gridtemplateButtons.CommandName.ToString().ToLower() == "managecards")
           {
               //TODO
           }
           if (gridtemplateButtons.CommandName.ToString().ToLower() == "exporttoexcel")
           {
               ConfigureExport(RadGridTrafficSummary);
               RadGridTrafficSummary.MasterTableView.Items[0].Expanded = true;
               RadGridTrafficSummary.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
               RadGrid detailRadGrid = (RadGrid)RadGridTrafficSummary.MasterTableView.Items[0].ChildItem.FindControl("RadGridTrafficImsiDetails");
               detailRadGrid.AllowFilteringByColumn = false;
               detailRadGrid.AllowSorting = false;
               detailRadGrid.GroupingEnabled = false;
               detailRadGrid.Rebind();
               RadGridTrafficSummary.MasterTableView.ExportToExcel();
 
               detailRadGrid.AllowFilteringByColumn = true;
               detailRadGrid.AllowSorting = true;
               detailRadGrid.GroupingEnabled = true;
           }
           if (gridtemplateButtons.CommandName.ToString().ToLower() == "exporttocsv")
           {
               ConfigureExport(RadGridTrafficSummary);
               RadGridTrafficSummary.MasterTableView.Items[0].Expanded = true;
               RadGridTrafficSummary.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
 
               RadGridTrafficSummary.Rebind();
               RadGridTrafficSummary.MasterTableView.ExportToCSV();
           }
       }
private void ConfigureExport(object sender)
        {
            (sender as RadGrid).MasterTableView.HierarchyDefaultExpanded = true;
            (sender as RadGrid).ExportSettings.ExportOnlyData = true;
            (sender as RadGrid).ExportSettings.IgnorePaging = true;
}
protected void RadGridTrafficSummary_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridNestedViewItem)
            {
                (e.Item.FindControl("RadGridTrafficImsiDetails") as RadGrid).Rebind();
            }
        }
0
Daniel
Telerik team
answered on 13 May 2011, 11:03 AM
Hello Peter,

The CSV file format is very simple - it does not support nested/hierarchical structures.

As to the other question - please note that you don't have to re-enable the grouping/filtering/sorting/etc after exporting since all these changes will be visible in the exported file only.

I recommend that you remove the code shown with strikethrough style:

detailRadGrid.AllowFilteringByColumn = false;
detailRadGrid.AllowSorting = false;
detailRadGrid.GroupingEnabled = false;
detailRadGrid.Rebind();
RadGridTrafficSummary.MasterTableView.ExportToExcel();

detailRadGrid.AllowFilteringByColumn = true;
detailRadGrid.AllowSorting = true;
detailRadGrid.GroupingEnabled = true;

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Peter
Top achievements
Rank 1
Share this question
or