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

PDF export; hierarchical Rad Grid selected row do not properly out put Master/Detail Table columns without clicking expand column

2 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 15 Oct 2010, 10:41 PM
Hi there,

I am using ASP.Net Ajax 2010, relase Q2 with Vstudio 2008 SP1.

I have a hierarchical Rad Grid, that only the selected Master Table row needs to be exported (i.e. Master row and all related Detail  Data). 

Attached is my Grid (hierarchy.jpg). If I do not expand the Master Row and click export, it just export Master Row Data (hierarchy export.jpg) not detail table data But If I expand the Master row, and click export it  does  output Master Detail Data (hierarchy export After Clicking Expand.jpg).

My question is that can I export the Master/Detal related row without expanding the Master Table row? My users will not be happy to expand the row first and later click the export button to export the data.  Basically I want the result set will be (hierarchy export After Clicking Expand.jpg) without expanding the Master Table row.

Below is my complete code. Thanks

Gc_0620
_____

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
         
        <telerik:RadGrid Skin="Sunset" AutoGenerateEditColumn="true" ID="RadGrid1" ShowStatusBar="true"
            DataSourceID="SqlDataSource1" runat="server" AutoGenerateColumns="False" 
            AllowPaging="True" GridLines="None" PageSize="10">
            <PagerStyle Mode="NumericPages"></PagerStyle>
            <MasterTableView HierarchyLoadMode="ServerOnDemand" DataSourceID="SqlDataSource1"
                DataKeyNames="CustomerID" AllowMultiColumnSorting="True" CommandItemDisplay="None">
                <DetailTables>
                    <telerik:GridTableView Name="Orders" DataKeyNames="OrderID" CommandItemDisplay="None"
                        DataSourceID="SqlDataSource2" Width="100%" runat="server">
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />
                        </ParentTableRelation>
                        <Columns>
                            <telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton"
                                DataField="OrderID" UniqueName="OrderID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Date Ordered" HeaderButtonType="TextButton"
                                DataField="OrderDate" UniqueName="OrderDate" DataFormatString="{0:D}">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="Freight" HeaderText="Freight" HeaderButtonType="TextButton"
                                DataField="Freight" UniqueName="Freight">
                            </telerik:GridBoundColumn>
                        </Columns>
                        <SortExpressions>
                            <telerik:GridSortExpression FieldName="OrderDate"></telerik:GridSortExpression>
                        </SortExpressions>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="CustomerID" HeaderText="CustomerID" HeaderButtonType="TextButton"
                        DataField="CustomerID" UniqueName="CustomerID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Contact Name" HeaderButtonType="TextButton"
                        DataField="ContactName" UniqueName="ContactName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="CompanyName" HeaderText="Company" HeaderButtonType="TextButton"
                        DataField="CompanyName" UniqueName="CompanyName">
                    </telerik:GridBoundColumn>
                </Columns>
                <SortExpressions>
                    <telerik:GridSortExpression FieldName="CompanyName"></telerik:GridSortExpression>
                </SortExpressions>
            </MasterTableView>
            <ClientSettings>
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
        </telerik:RadGrid>
          
        <br /> <br />
         <asp:Button ID="Button1" runat="server" Text="Export to PDF selected items with Child Items" OnClick="Button1_Click" />
        <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Customers"
            runat="server"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID"
            runat="server">
            <SelectParameters>
                <asp:SessionParameter Name="CustomerID" SessionField="CustomerID" Type="string" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
     
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
  
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
  
    }
  
  
  
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
  
    }
  
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (RadGrid1.SelectedItems.Count != 0)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                if (!item.Selected)
                    item.Visible = false;
            }
        }
      
        RadGrid1.ExportSettings.OpenInNewWindow = true;
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
        RadGrid1.MasterTableView.ExportToPdf();
    }
  
  
}
 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin
Telerik team
answered on 21 Oct 2010, 02:26 PM
Hello gc_0620,

You can acieve this by setting programatically
RadGrid1.MasterTableView.HierarchyDefaultExpanded = true; in the item command for exporting the grid. Thus when exporting the hierarchy will be expanded and in the web page stay collapsed. Here is a short code snippet on how to do this:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.ExportToPdfCommandName)
       {
           RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
           RadGrid1.MasterTableView.Rebind();
       }
   }


Kind regards,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
gc_0620
Top achievements
Rank 1
answered on 22 Oct 2010, 07:46 PM
Thanks Marin. It did the trick.

Have a good weekend..

Sincerely

gc_0620
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Marin
Telerik team
gc_0620
Top achievements
Rank 1
Share this question
or