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

RadGrid exporting with NestedViewTemplate

5 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 1
Ajay asked on 06 Jun 2011, 11:14 AM
Hi,
I am trying to export a radgrid to pdf which is having data in NestedViewTemplate.
When I try to do so the error come, please see the attached snapshot for error details.

My code is as belows:

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <telerik:RadGrid ID="radGridShippedOrders" runat="server" GridLines="None" AllowPaging="True"
            PageSize="15" AllowSorting="True" AutoGenerateColumns="false" ShowStatusBar="true" ShowHeader="false"
            HorizontalAlign="NotSet" AllowMultiRowEdit="false" OnNeedDataSource="radGridShippedOrders_NeedDataSource" 
             OnItemCommand="radGridShippedOrders_OnItemCommand" AllowCustomPaging="true" VirtualItemCount="5"
            Width="800px" AllowMultiRowSelection="False" AllowFilteringByColumn="true" ShowGroupPanel="True">
            <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"></PagerStyle>
            
            <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
                 <Pdf PageTitle="Shipped Orders" />
                 <Excel Format=ExcelML />
            </ExportSettings>


            <MasterTableView GroupLoadMode="Client" CommandItemDisplay="None" DataKeyNames="OAHSSQ" Name="MTVShippedOrders">
                <Columns>
                    <telerik:GridBoundColumn UniqueName="OAORGN" HeaderText="OAORGN" DataField="OAORGN">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="OAHSSQ" HeaderText="OAHSSQ" DataField="OAHSSQ">
                    </telerik:GridBoundColumn>
                </Columns>
<NestedViewTemplate>
                    <b>Invoice Header</b><br />
                    <telerik:RadGrid ID="radGridInvoiceHeader" runat="server" GridLines="None" AllowPaging="True"
                        PageSize="20" AllowSorting="True" AutoGenerateColumns="false" ShowStatusBar="false" ShowHeader="false"
                        HorizontalAlign="NotSet" AllowMultiRowEdit="false" OnNeedDataSource="radGridInvoiceHeader_NeedDataSource"
                        Width="100%" AllowMultiRowSelection="False" AllowFilteringByColumn="false">
                        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"></PagerStyle>
                        <ExportSettings ExportOnlyData="false" IgnorePaging="true" OpenInNewWindow="true">
                            <Pdf PageTitle="Invoice Header" />
                        </ExportSettings>
                        <MasterTableView CommandItemDisplay="Bottom">
                              <Columns>
                                <telerik:GridBoundColumn UniqueName="OHORNO" HeaderText="Order Number" DataField="OHORNO"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="OHCSNM" HeaderText="Customer Name" DataField="OHCSNM"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="OHCAD1" HeaderText="Sold To Add 1" DataField="OHCAD1"></telerik:GridBoundColumn>
</Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                    
                    <br />
                    <b>Invoice Details</b><br />
                    <telerik:RadGrid ID="radGridInvoiceDetails" runat="server" GridLines="None" AllowPaging="True"
                        PageSize="20" AllowSorting="True" AutoGenerateColumns="false" ShowStatusBar="false" ShowHeader="false"
                        HorizontalAlign="NotSet" AllowMultiRowEdit="false" OnNeedDataSource="radGridInvoiceDetails_NeedDataSource"
                        Width="100%" AllowMultiRowSelection="False" AllowFilteringByColumn="false" OnItemDataBound="radGridInvoiceDetails_ItemDataBound">
                        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"></PagerStyle>
                        <ExportSettings ExportOnlyData="false" IgnorePaging="true" OpenInNewWindow="true">
                            <Pdf PageTitle="Invoice Header" />
                        </ExportSettings>
                        <MasterTableView CommandItemDisplay="Bottom" ShowFooter="true">
<Columns>
                                <telerik:GridBoundColumn UniqueName="ODITNO" HeaderText="Item Number" DataField="ODITNO"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="ODITD1" HeaderText="Item Description" DataField="ODITD1"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="ODQTOR" HeaderText="Quantity Ordered" DataField="ODQTOR"></telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>


                </NestedViewTemplate>


            </MasterTableView>
             <ClientSettings AllowGroupExpandCollapse="True" ReorderColumnsOnClient="True" AllowDragToGroup="True"
                AllowColumnsReorder="True">
            </ClientSettings>
             <GroupingSettings ShowUnGroupButton="true" />
        </telerik:RadGrid>
    

CODE BEHIND
protected void btnExportToPDF_Click(object sender, EventArgs e)
        {
            radGridShippedOrders.ExportSettings.OpenInNewWindow = true;
            radGridShippedOrders.ExportSettings.ExportOnlyData = true;
            radGridShippedOrders.ExportSettings.IgnorePaging = true;

            foreach (GridDataItem gi in radGridShippedOrders.MasterTableView.Items)
            {
                gi.Expanded = true;
                if (gi.HasChildItems)
                {
                    RadGrid rgHeader = (RadGrid)gi.ChildItem.NestedViewCell.Controls[0].Controls[1];
                    rgHeader.Rebind();

                    RadGrid rgDetails = ((RadGrid)gi.ChildItem.NestedViewCell.Controls[0].FindControl("radGridInvoiceDetails"));
                    rgDetails.Rebind();
                } 
            }
            radGridShippedOrders.MasterTableView.HierarchyDefaultExpanded = true;
            radGridShippedOrders.MasterTableView.ExportToPdf();
        }

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Jun 2011, 12:20 PM
Hello Ajay,

This issue arises when a DIV element with specified dimensions or absolute positioning is present in the grid. Remove the relevant width/height/position attributes to avoid this exception. Check the following help documentation which explains more about this.
PDF export.

Thanks,
Princy
0
Ajay
Top achievements
Rank 1
answered on 07 Jun 2011, 06:05 AM
Hi Princy,

That worked perfectly fine after removing the width from radgrids.
But still there is an issue, the radgrids inside the NestedViewTemplate are not included/rendered in the exported pdf document.
The static content inside the NestedViewTemplate is present in the exported pdf.

Please suggest something for this.
0
Ajay
Top achievements
Rank 1
answered on 09 Jun 2011, 11:35 AM
Hi Princy,

Any update on this?

Also how can I exclude controls inside NestedViewTemplate while exporting?


Thanks
Ajay
0
Marlon Santos
Top achievements
Rank 1
answered on 10 Jun 2011, 02:20 PM
Did you ever figure this issue out?

0
Ajay
Top achievements
Rank 1
answered on 13 Jun 2011, 06:20 AM
Hi Marlon,

Luckily I solved the issue.
Instead of exporting the grid on button click, I exported the grid in the radGrid_OnPreRender event.

Now I am stuck in another issue.
When I try to sort any column, then the NeedDatasource event of all RadGrids inside the NestedTemplateView are called (even if the parent is not in expanded mode). This causes page to take a lot of time to sort the grid.

Any idea how to stop this?

Thanks 
Ajay
Tags
Grid
Asked by
Ajay
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ajay
Top achievements
Rank 1
Marlon Santos
Top achievements
Rank 1
Share this question
or