I have a Radgrid that has a MasterTable and a DetailsTable. They basically have the same columns, the Master is top level view and the details is broken down data. However, when I export the data to Excel the columns are no longer aligned. How can I get them to align?
Thank You in advance!
Thank You in advance!
3 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 28 Feb 2014, 05:07 AM
Hi Mike,
I'm not clear about the issue. Below is a sample code snippet that works fine at my end. Can you please try and let me know if any concern. Provide your code snippet as well as a screenshot of the issue you are facing.
ASPX:
C#:
Thanks,
Shinu
I'm not clear about the issue. Below is a sample code snippet that works fine at my end. Can you please try and let me know if any concern. Provide your code snippet as well as a screenshot of the issue you are facing.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"False"
EnableHierarchyExpandAll
=
"true"
RetainExpandStateOnRebind
=
"true"
AllowPaging
=
"True"
AllowSorting
=
"true"
OnDetailTableDataBind
=
"RadGrid1_DetailTableDataBind"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
>
<
MasterTableView
DataKeyNames
=
"CustomerID"
HierarchyLoadMode
=
"Client"
CommandItemDisplay
=
"Top"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"OrderID"
Name
=
"Orders"
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"OrderID"
HeaderText
=
"OrderID"
DataField
=
"OrderID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"OrderDate"
HeaderText
=
"Date Ordered"
DataField
=
"OrderDate"
UniqueName
=
"OrderDate"
DataFormatString
=
"{0:D}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"Freight"
HeaderText
=
"Freight"
DataField
=
"Freight"
UniqueName
=
"Freight"
>
</
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
>
<
asp:Button
ID
=
"ExcelExport"
runat
=
"server"
Text
=
"Export To Excel"
OnClick
=
"ExcelExport_Click"
/>
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
;
}
}
}
protected
void
ExcelExport_Click(
object
sender, EventArgs e)
{
RadGrid1.ExportSettings.ExportOnlyData =
true
;
RadGrid1.ExportSettings.HideStructureColumns =
true
;
RadGrid1.MasterTableView.HierarchyDefaultExpanded =
true
;
RadGrid1.Rebind();
RadGrid1.MasterTableView.ExportToExcel();
}
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;
}
Thanks,
Shinu
0

Mike
Top achievements
Rank 1
answered on 28 Feb 2014, 05:56 PM
Thank you for the reply. What I am looking for is to have the columns in the Master Table align with the columns in the Details Table. They are the same, but the details table is broken down line by line versus rolled up totals.
Currently, the details table columns are too far to the right.
Currently, the details table columns are too far to the right.
0

Shinu
Top achievements
Rank 2
answered on 03 Mar 2014, 03:38 AM
Hi Mike,
Please take a look at this article on Aligning columns in each level of hierarchical grid.
Thanks,
Shinu
Please take a look at this article on Aligning columns in each level of hierarchical grid.
Thanks,
Shinu