I have a problem to while exporting the data of Hierarchical RadGrid data in pdf form.
Please see the attached image.
It is not showing proper data. And i am writng the code to export the pdf of radgrid on a Simple Image Button Click.
Please help me. It is urgent for me. Thanks in advance.
Please see the attached image.
It is not showing proper data. And i am writng the code to export the pdf of radgrid on a Simple Image Button Click.
Please help me. It is urgent for me. Thanks in advance.
7 Answers, 1 is accepted
0
Hello Kalpna,
Please try enabling the RetainExpandStateOnRebind property.
Let me know whether this helps.
Regards,
Daniel
Telerik
Please try enabling the RetainExpandStateOnRebind property.
Let me know whether this helps.
Regards,
Daniel
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Kalpna
Top achievements
Rank 1
answered on 26 Feb 2014, 10:35 AM
Hello Daniel,
RadGrid is not showing this property 'RetainExpandStateOnRebind '.
And now i want to set the width of column of detail table view in export to pdf. But i am unable to set them. This is my pdf screen-shot which i got after export to pdf. Please help me to apply style on each column of detail table view.
Please help me. its urgent for me.
RadGrid is not showing this property 'RetainExpandStateOnRebind '.
And now i want to set the width of column of detail table view in export to pdf. But i am unable to set them. This is my pdf screen-shot which i got after export to pdf. Please help me to apply style on each column of detail table view.
Please help me. its urgent for me.
0
Princy
Top achievements
Rank 2
answered on 26 Feb 2014, 12:01 PM
Hi Kalpna,
The RetainExpandStateOnRebind has been introduced in Q3 2013 BETA.
To set the width of the detail table on export to PDF please try the following code snippet.
C#:
Thanks,
Princy
The RetainExpandStateOnRebind has been introduced in Q3 2013 BETA.
To set the width of the detail table on export to PDF please try the following code snippet.
C#:
protected
void
PDFExportbtn_Click(
object
sender, EventArgs e)
{
RadGrid1.MasterTableView.HierarchyDefaultExpanded =
true
;
if
(RadGrid1.MasterTableView.HasDetailTables)
{
foreach
(GridTableView gridTableView
in
RadGrid1.MasterTableView.DetailTables)
{
gridTableView.HierarchyDefaultExpanded =
true
;
gridTableView.GetColumn(
"ColumnUniqueName"
).HeaderStyle.Width = Unit.Pixel(300);
}
}
RadGrid1.Rebind();
RadGrid1.MasterTableView.ExportToPdf();
}
Thanks,
Princy
0
Kalpna
Top achievements
Rank 1
answered on 26 Feb 2014, 12:34 PM
Hello Princy,
I have already done this. But this is not working.
I have already done this. But this is not working.
0
Princy
Top achievements
Rank 2
answered on 27 Feb 2014, 04:40 AM
Hi Kalpna,
Please take a look at the sample code snippet it works fine at my end. Provide your code snippet if this doesn't help.
ASPX:
C#:
Thanks,
Princy
Please take a look at the sample code snippet it works fine at my end. Provide your code snippet if this doesn't help.
ASPX:
<
asp:Button
ID
=
"PDFExportbtn"
runat
=
"server"
Text
=
"Export to PDF"
OnClick
=
"PDFExportbtn_Click"
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"False"
RetainExpandStateOnRebind
=
"true"
AllowPaging
=
"True"
OnDetailTableDataBind
=
"RadGrid1_DetailTableDataBind"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowSorting
=
"true"
>
<
MasterTableView
DataKeyNames
=
"CustomerID"
HierarchyLoadMode
=
"Client"
CommandItemDisplay
=
"Top"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"OrderID"
Name
=
"Orders"
Width
=
"100%"
RetainExpandStateOnRebind
=
"true"
HierarchyLoadMode
=
"Client"
HierarchyDefaultExpanded
=
"false"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"OrderID,UnitPrice"
Name
=
"OrderDetails"
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"UnitPrice"
HeaderText
=
"Unit Price"
DataField
=
"UnitPrice"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Quantity"
HeaderText
=
"Quantity"
DataField
=
"Quantity"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Discount"
HeaderText
=
"Discount"
DataField
=
"Discount"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"OrderID"
HeaderText
=
"OrderID"
DataField
=
"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"
DataField
=
"Freight"
UniqueName
=
"Freight"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"ShipCity"
HeaderText
=
"ShipCity"
DataField
=
"ShipCity"
UniqueName
=
"ShipCity"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"CustomerID"
HeaderText
=
"CustomerID"
DataField
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"ContactName"
HeaderText
=
"Contact Name"
DataField
=
"ContactName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"CompanyName"
HeaderText
=
"Company"
DataField
=
"CompanyName"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
if
(!e.IsFromDetailTable)
{
RadGrid1.DataSource = GetDataTable(
"Select * from Customers"
);
}
}
protected
void
RadGrid1_DetailTableDataBind(
object
source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
switch
(e.DetailTableView.Name)
{
case
"Orders"
:
{
string
CustomerID = dataItem.GetDataKeyValue(
"CustomerID"
).ToString();
e.DetailTableView.DataSource = GetDataTable(
"SELECT * FROM Orders WHERE CustomerID = '"
+ CustomerID +
"'"
);
break
;
}
case
"OrderDetails"
:
{
string
OrderID = dataItem.GetDataKeyValue(
"OrderID"
).ToString();
e.DetailTableView.DataSource = GetDataTable(
"SELECT * FROM [Order Details] WHERE OrderID = "
+ OrderID);
break
;
}
}
}
public
DataTable GetDataTable(
string
query)
{
String ConnString = ConfigurationManager.ConnectionStrings[
"Northwind_newConnectionString3"
].ConnectionString;
SqlConnection conn =
new
SqlConnection(ConnString);
SqlDataAdapter adapter =
new
SqlDataAdapter();
adapter.SelectCommand =
new
SqlCommand(query, conn);
DataTable myDataTable =
new
DataTable();
conn.Open();
try
{
adapter.Fill(myDataTable);
}
finally
{
conn.Close();
}
return
myDataTable;
}
protected
void
PDFExportbtn_Click(
object
sender, EventArgs e)
{
RadGrid1.MasterTableView.HierarchyDefaultExpanded =
true
;
if
(RadGrid1.MasterTableView.HasDetailTables)
{
foreach
(GridTableView gridTableView
in
RadGrid1.MasterTableView.DetailTables)
{
gridTableView.HierarchyDefaultExpanded =
true
;
gridTableView.GetColumn(
"OrderID"
).HeaderStyle.Width = Unit.Pixel(300);
if
(gridTableView.HasDetailTables)
{
foreach
(GridTableView gridTableViewinner
in
gridTableView.DetailTables)
{
gridTableViewinner.GetColumn(
"UnitPrice"
).HeaderStyle.Width = Unit.Pixel(300);
}
}
}
}
RadGrid1.Rebind();
RadGrid1.MasterTableView.ExportToPdf();
}
Thanks,
Princy
0
Srujan
Top achievements
Rank 1
answered on 03 Mar 2014, 11:17 PM
Hi Princy ,
I am using below code and when I export to PDF it shows as file corrupted , can you please suggest to proceed further
RadGrid.MasterTableView.HierarchyDefaultExpanded = true;
if (RadGrid.MasterTableView.HasDetailTables)
{
foreach (GridTableView gridTableView in RadGrid.MasterTableView.DetailTables)
{
gridTableView.HierarchyDefaultExpanded = true;
}
}
RadGrid.Rebind();
RadGrid.MasterTableView.ExportToPdf();
I am using below code and when I export to PDF it shows as file corrupted , can you please suggest to proceed further
RadGrid.MasterTableView.HierarchyDefaultExpanded = true;
if (RadGrid.MasterTableView.HasDetailTables)
{
foreach (GridTableView gridTableView in RadGrid.MasterTableView.DetailTables)
{
gridTableView.HierarchyDefaultExpanded = true;
}
}
RadGrid.Rebind();
RadGrid.MasterTableView.ExportToPdf();
0
Princy
Top achievements
Rank 2
answered on 04 Mar 2014, 04:11 AM
Hi Srujan,
I'm not aware of such an issue. I was not able to replicate it on my side. Try to upgrade to the latest version and check. Please provide your full code snippet to identify the issue. I have tried the sample code given above and it exports fine to PDF. Please take a look at this article on PDF Export for more information.
Thanks,
Princy
I'm not aware of such an issue. I was not able to replicate it on my side. Try to upgrade to the latest version and check. Please provide your full code snippet to identify the issue. I have tried the sample code given above and it exports fine to PDF. Please take a look at this article on PDF Export for more information.
Thanks,
Princy