Would you provide a sample for RadGrid Q1 2010 Export and Grouping together?
I tried to build a page with your drag-&-drop column header grouping, then export the grouped grid data to excel.
Thanks
daniel
18 Answers, 1 is accepted
I'm not sure whether you prefer the HTML Excel or ExcelML format so I picked up the latter.
I hope this helps.
Best regards,
Daniel
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.
I used your sample pages, and remove SQlDatSource, bind the RADGrid to a datatable in codebehind, grouping is fine, but if I click subgroup arrow try to minimize the subgroup, following error:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
google this error, I added EnableEventValidation="false" to page like following:
<%
@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true"
no error any more, but subgroup min arrow not working.
Is it because codebehind databind() not working properly?
We could not use SQlDatSource in our project since we have custom datalogic to create our datatable..
thanks
Judging by the error message, I suppose you bind RadGrid on every page load. I recommend you use advanced data-binding to avoid such issues:
Advanced Data-binding help topic
Advanced Data Binding online demo
Let me know if you need further assistance.
Best regards,
Daniel
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.
we could not load RadGrid in Page_Load event, we need load it only after user click button:
protected void Button1_Click(object sender, System.EventArgs e)
{
//loadRadGrid here.
}
but if I put OnNeedDataSource in html,
<telerik:RadGrid ID="RadGrid1" runat="server"
OnNeedDataSource="RadGrid1_NeedDataSource"
it will automatically load the RadGrid when Page_Load.
How to load radGrid only after button clicked?
thanks
daniel
OnNeedDataSource="RadGrid1_NeedDataSource" and
RadGrid1.MasterTableView.ExportToExcel();
following error:
Script controls may not be registered after PreRender.
I tested to commen out // RadGrid1.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML; like following:
protected void ExcelExport(object sender, System.EventArgs e)
{
ConfigureExport();
// RadGrid1.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;
RadGrid1.MasterTableView.ExportToExcel();
}
I could export to Excel Html format without error.
How to export ExcelML format?
Please advise how to fix.
thanks
daniel
Question 1: we could not load RadGrid in Page_Load event, we need load it only after user click button:
You don't need to bind RadGrid on initial load - you can use an if statement in the NeedDataSource handler and bind RadGrid only if the desired condition is satisfied.
Question 2: Problem to use ExcelML
Do you use RadFilter and if yes, which version of RadControls you have? If this is not the case, please post your markup here (or attach the code to a support ticket) so I can examine your approach.
Best regards,
Daniel
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.
1.
How to export ExcelML format?
if I comment out
//RadGrid1.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;
I could export Excel Html file, but if uncommen it, error: Script controls may not be registered after PreRender.
2.
How to export the collapsed grouped grid?
When I export excel html, only data in expanded group could been exported, how to export all the data for single page export and for all the pages export?
I tried some code(see my commented code in export function), but if I could export the data in collapsed group in single page, then all the pages export could only export data in expanded group.
Thanks for the help.
here is the html:
<telerik:RadGrid ID="RadGrid1" runat="server"
OnNeedDataSource="RadGrid1_NeedDataSource"
AllowFilteringByColumn="True" EnableViewState="true"
AllowPaging="True" AllowSorting="True"
GridLines="None" ShowGroupPanel="True" Width="100%">
<
MasterTableView AutoGenerateColumns="False" GroupsDefaultExpanded="true" >
<
RowIndicatorColumn>
<
HeaderStyle Width="20px"></HeaderStyle>
</
RowIndicatorColumn>
<
ExpandCollapseColumn>
<
HeaderStyle Width="20px"></HeaderStyle>
</
ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn datafield="ID" headertext="Id" SortExpression="ID" UniqueName="ID"/>
<telerik:GridBoundColumn datafield="DESCR" headertext="Name" SortExpression="DESCR" UniqueName="DESCR"/>
<telerik:GridBoundColumn datafield="FIRST_NAME" headertext="First Name" SortExpression="FIRST_NAME" UniqueName="FIRST_NAME"/>
<telerik:GridBoundColumn datafield="MIDDLE_NAME" headertext="Middle Name" SortExpression="MIDDLE_NAME" UniqueName="MIDDLE_NAME"/>
<telerik:GridBoundColumn datafield="LAST_NAME" headertext="Last Name" SortExpression="LAST_NAME" UniqueName="LAST_NAME"/>
</Columns>
</
MasterTableView>
<ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True"
ReorderColumnsOnClient="True" >
<Selecting AllowRowSelect="True" />
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
</telerik:RadGrid>
here is the c# code:
#region
telerik export
protected void ExcelExport(object sender, System.EventArgs e)
{
ConfigureExport();
//// RadGrid1.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;
// foreach (GridItem gi in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
// {
// gi.Expanded = true;
// }
// RadGrid1.ExportSettings.IgnorePaging = chkIgnorePaging.Checked;
RadGrid1.MasterTableView.ExportToExcel();
}
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||
e.CommandName == Telerik.Web.UI.
RadGrid.ExportToWordCommandName ||
e.CommandName == Telerik.Web.UI.
RadGrid.ExportToCsvCommandName ||
e.CommandName == Telerik.Web.UI.
RadGrid.ExportToPdfCommandName)
{
ConfigureExport();
}
}
protected void RadGrid1_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e)
{
if (e.RowType == Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.DataRow)
{
if (e.Row.Cells[0] != null && ((string)e.Row.Cells[0].Data.DataItem).Contains("U"))
{
e.Row.Cells[0].StyleValue =
"MyCustomStyle";
}
}
}
protected void RadGrid1_ExcelMLExportStylesCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs e)
{
foreach (Telerik.Web.UI.GridExcelBuilder.StyleElement style in e.Styles)
{
if (style.Id == "headerStyle")
{
style.FontStyle.Bold =
true;
style.FontStyle.Color = System.Drawing.
Color.Gainsboro;
style.InteriorStyle.Color = System.Drawing.
Color.Wheat;
style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.
InteriorPatternType.Solid;
}
else if (style.Id == "itemStyle")
{
style.InteriorStyle.Color = System.Drawing.
Color.WhiteSmoke;
style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.
InteriorPatternType.Solid;
}
else if (style.Id == "alternatingItemStyle")
{
style.InteriorStyle.Color = System.Drawing.
Color.LightGray;
style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.
InteriorPatternType.Solid;
}
}
Telerik.Web.UI.GridExcelBuilder.
StyleElement myStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("MyCustomStyle");
myStyle.FontStyle.Bold =
true;
myStyle.FontStyle.Italic =
true;
myStyle.InteriorStyle.Color = System.Drawing.
Color.Gray;
myStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.
InteriorPatternType.Solid;
e.Styles.Add(myStyle);
}
public void ConfigureExport()
{
// RadGrid1.MasterTableView.GroupsDefaultExpanded = true;
RadGrid1.ExportSettings.ExportOnlyData = chkOnlyData.Checked;
RadGrid1.ExportSettings.IgnorePaging = chkIgnorePaging.Checked;
//foreach (GridItem gi in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
//{
// if (chkIgnorePaging.Checked == false)
// {
// gi.Expanded = true;
// }
// //else
// //{
// // gi.Expanded = false;
/ //}
//}
// RadGrid1.ExportSettings.OpenInNewWindow = chkOpenNewBrowser.Checked;
RadGrid1.ExportSettings.OpenInNewWindow = true;
}
#endregion
I created a runnable sample project based on the provided code. May I ask you to modify it so that I can reproduce the aforementioned problems on my end?
Please note that the groups will always be in expanded state when exporting to ExcelML.
Best regards,
Daniel
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.
I am in the middle of a task now, will test it after my current project finished.
daniel liu
I'm in the same trouble as described above.
I'm getting the same message error "Scripts may not be registered after PreRender" with my export settings in ExcelML mode.
There's a solution I can implement here to workaround this problem?
Greetings.
Could you please post your code in this thread? I'm not sure what exactly causes this exception so I will be grateful if you help me reproduce the problem on my end.
Best regards,
Daniel
the Telerik team
I can able to export Master records only in Excel Format. Child records comes with blank cells. How can i solve this?
Thanks in advance.
Regards,
Balaji
Please try the sample code snippet which shows how to export hierarchy grid. Provide your full code snippet if this doesn't help.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AllowSorting="true" AllowPaging="true" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand"> <ExportSettings ExportOnlyData="true" OpenInNewWindow="true" IgnorePaging="true"> </ExportSettings> <MasterTableView DataKeyNames="CountryID" Name="Country" CommandItemDisplay="Top"> <CommandItemSettings ShowExportToExcelButton="true" /> <DetailTables> <telerik:GridTableView DataKeyNames="StateID" Name="State"> <DetailTables> <telerik:GridTableView DataKeyNames="StateID" Name="District"> <Columns> <telerik:GridBoundColumn HeaderText="DistrictID" DataField="DistrictID" UniqueName="DistrictID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="DistrictName" DataField="DistrictName" UniqueName="DistrictName"> </telerik:GridBoundColumn> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridBoundColumn HeaderText="StateID" DataField="StateID" UniqueName="StateID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="StateName" DataField="StateName" UniqueName="StateName"> </telerik:GridBoundColumn> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridBoundColumn SortExpression="CountryID" HeaderText="CountryID" DataField="CountryID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="CountryName" HeaderText="CountryName" DataField="CountryName"> </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 Country"); }}protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e){ GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; switch (e.DetailTableView.Name) { case "State": { string CountryID = dataItem.GetDataKeyValue("CountryID").ToString(); e.DetailTableView.DataSource = GetDataTable("SELECT * FROM State WHERE CountryID = '" + CountryID + "'"); break; } case "District": { string StateID = dataItem.GetDataKeyValue("StateID").ToString(); e.DetailTableView.DataSource = GetDataTable("SELECT * FROM District WHERE StateID = '" + StateID + "'"); break; } }}public DataTable GetDataTable(string query){ String ConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].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 RadGrid1_ItemCommand(object sender, GridCommandEventArgs e){ if (e.CommandName == RadGrid.ExportToExcelCommandName) { RadGrid1.MasterTableView.HierarchyDefaultExpanded = true; RadGrid1.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true; }}Thanks,
Princy
Thanks for your reply. In this i am getting output in HTML format. I need the result in ExcelML Format. In ExcelML format, i am getting same issue again. Please solve this issue. Once again thanks.
Best Regards,
Balaji
Unfortunately I'm unable to replicate this issue at my end.
Thanks,
Princy
I am using UpdatePanel in my page. I attached my Code here. If Possible check this code with your side and suggest me for the solution.
aspx:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <telerik:RadSkinManager ID="RadSkinManager1" runat="server" Skin="WebBlue"></telerik:RadSkinManager> <style type="text/css"> .RadGrid_SkinName input { border: 0px; background-color: transparent; } </style><asp:UpdateProgress ID="updProg" runat="server" DisplayAfter="0"> <ProgressTemplate> <div id="Layer1" style="position: absolute; z-index: 1; left: 50%; top: 34%;"> <img src="../Images/loading2.gif" alt="Loading" border="0" /> </div> </ProgressTemplate> </asp:UpdateProgress> <asp:UpdatePanel ID="updSearch" runat="server" ChildrenAsTriggers="true"> <ContentTemplate><telerik:RadGrid ID="AttestationReviewGrid" ShowStatusBar="True" GridLines="None" CellSpacing="0" runat="server" AutoGenerateColumns="False" PageSize="100" AllowSorting="True" AllowPaging="True" OnDetailTableDataBind="AttestationReviewGrid_DetailTableDataBind" OnPreRender="AttestationReviewGrid_PreRender" OnNeedDataSource="AttestationReviewGrid_NeedDataSource" OnItemDataBound="AttestationReviewGrid_ItemDataBound" OnItemCreated="AttestationReviewGrid_ItemCreated" OnItemCommand="AttestationReviewGrid_ItemCommand"> <HeaderStyle Font-Bold="True" /> <PagerStyle Mode="NumericPages"></PagerStyle> <%--<ExportSettings HideStructureColumns="true" IgnorePaging="true" ExportOnlyData="true" Excel-Format="ExcelML" OpenInNewWindow="true"> <Pdf PageHeight="210mm" AllowPrinting="true" PageWidth="330mm" DefaultFontFamily="Arial Unicode MS" PageTopMargin="45mm" BorderStyle="Medium" BorderColor="#666666" BorderType="AllBorders" ForceTextWrap="true"> </Pdf> <Excel Format="ExcelML"></Excel> </ExportSettings>--%> <ExportSettings ExportOnlyData="true" OpenInNewWindow="true" IgnorePaging="true" Excel-Format="ExcelML"> <Pdf PageHeight="210mm" AllowPrinting="true" PageWidth="330mm" DefaultFontFamily="Arial Unicode MS" PageTopMargin="45mm" BorderStyle="Medium" BorderColor="#666666" BorderType="AllBorders" ForceTextWrap="true"> </Pdf> </ExportSettings> <%--<ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True"> <Selecting AllowRowSelect="True" /> <Scrolling AllowScroll="True" UseStaticHeaders="True" /> </ClientSettings>--%> <MasterTableView EnableHierarchyExpandAll="true" CommandItemDisplay="Top" AutoGenerateColumns="false" GroupsDefaultExpanded="false" AllowMultiColumnSorting="True" DataKeyNames="ReviewEndpointId"> <%--<CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" ShowExportToExcelButton="true" ShowExportToPdfButton="true" ShowExportToCsvButton="true"></CommandItemSettings>--%> <CommandItemTemplate> <asp:Button ID="bXls" runat="server" CommandName="ExportToExcel" Text="Export To Excel" OnClick="bXls_Click" /> <asp:Button ID="bPdf" runat="server" CommandName="ExportToPDF" Text="Export To PDF" OnClick="bPdf_Click" /> </CommandItemTemplate> <DetailTables> <telerik:GridTableView EnableHierarchyExpandAll="true" ShowHeader="true" DataKeyNames="L2DetailId" Width="100%" runat="server" Name="EPSystemL2" NoDetailRecordsText="No records found."> <%-- Start EPSysytem Section --%> <DetailTables> <telerik:GridTableView EnableHierarchyExpandAll="true" DataKeyNames="L3DetailId" Width="100%" runat="server" Name="EPSystemL3" NoDetailRecordsText="No records found."> <DetailTables> <telerik:GridTableView EnableHierarchyExpandAll="true" DataKeyNames="sapLevel1DetailId" Width="100%" runat="server" Name="SAPOnlyDetails" NoDetailRecordsText="No records found."> <Columns> <telerik:GridBoundColumn SortExpression="sapLevel1Detail" HeaderText="TCodes" DataField="sapLevel1Detail" UniqueName="DetailSapLevel1GridBoundColumn"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="sapLevel1DetailDesc" HeaderText="Description" DataField="sapLevel1DetailDesc" UniqueName="DetailTypeSapLevel1GridBoundColumn"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn UniqueName="IsChangedSAPGridTemplateColumn" HeaderText="Changed" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right" Visible="false"> <ItemTemplate> <asp:Label ID="IsChangedSAPLabel" runat="server" Text='<%#Convert.ToBoolean(Eval("IsChanged")) ? "Yes" : "" %>' /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridTemplateColumn Display="false"> <ItemTemplate> <asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("L3DetailId") %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn SortExpression="AccessName" HeaderText="AccessName" DataField="AccessName" UniqueName="AccessNameL3GridBoundColumn"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="AccessType" HeaderText="AccessType" DataField="AccessType" UniqueName="AccessTypeL3GridBoundColumn"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn UniqueName="ApproveL3GridTemplateColumn" HeaderText="Approve" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:RadioButton ID="ApproveL3RadioButton" runat="server" AutoPostBack="true" GroupName="L3" OnCheckedChanged="ApproveL3RadioButton_CheckedChanged" CssClass="RadGrid_SkinName" Checked='<%#Convert.ToBoolean(Eval("Approve")) %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="RevokeL3GridTemplateColumn" HeaderText="Revoke" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:RadioButton ID="RevokeL3RadioButton" runat="server" AutoPostBack="true" GroupName="L3" OnCheckedChanged="RevokeL3RadioButton_CheckedChanged" CssClass="RadGrid_SkinName" Checked='<%#Convert.ToBoolean(Eval("Revoke")) %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="HiddenL3GridTemplateColumn" HeaderText="Hidden" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:RadioButton ID="HiddenL3RadioButton" runat="server" AutoPostBack="true" GroupName="L3" OnCheckedChanged="HiddenL3RadioButton_CheckedChanged" Checked='<%#Convert.ToBoolean(Eval("Hidden")) %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="IsChangedL3GridTemplateColumn" HeaderText="Changed" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:Label ID="IsChangedL3Label" runat="server" Text='<%#Convert.ToBoolean(Eval("IsChanged")) ? "Yes" : "" %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn SortExpression="PreviousAccess" HeaderText="Current Access" DataField="PreviousAccess" UniqueName="PreviousAccessL3GridBoundColumn" HeaderStyle-Width="105px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn HeaderText="Comments" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right" UniqueName="CommentsL3GridBoundColumn"> <ItemTemplate> <asp:ImageButton ID="AddCommentLinkButton" runat="server" ImageUrl="~/Images/icons/AddComments.png" Width="20px" Height="20px" Text="Add Comments" OnClick="AddCommentImageButton_Click" CommandArgument='<%#Eval("L3DetailId") %>' CommandName="EndpointSystemL3Comment"></asp:ImageButton> </ItemTemplate> <HeaderStyle HorizontalAlign="Left" /> </telerik:GridTemplateColumn> </Columns> </telerik:GridTableView> </DetailTables> <%--End EPSysytem Section--%> <Columns> <telerik:GridTemplateColumn Display="false"> <ItemTemplate> <asp:HiddenField ID="HiddenField2" runat="server" Value='<%#Eval("L2DetailId") %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn SortExpression="AccessName" HeaderText="Permission" DataField="AccessName" UniqueName="AccessNameL2GridBoundColumn"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="AccessType" HeaderText="Access Type" DataField="AccessType" UniqueName="AccessTypeL2GridBoundColumn"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn UniqueName="ResourceCompletePathL2GridBoundColumn" HeaderText="Page Detail" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%#Eval("ResourceType") %>'></asp:Label><br /> <asp:Label ID="Label1" runat="server" Text='<%#Eval("ResourceCompletePath") %>'></asp:Label> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="ApproveL2GridTemplateColumn" HeaderText="Approve" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:RadioButton ID="ApproveL2RadioButton" runat="server" AutoPostBack="true" GroupName="L2" OnCheckedChanged="ApproveL2RadioButton_CheckedChanged" CssClass="RadGrid_SkinName" Checked='<%#Convert.ToBoolean(Eval("Approve")) %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="RevokeL2GridTemplateColumn" HeaderText="Revoke" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:RadioButton ID="RevokeL2RadioButton" runat="server" AutoPostBack="true" GroupName="L2" OnCheckedChanged="RevokeL2RadioButton_CheckedChanged" CssClass="RadGrid_SkinName" Checked='<%#Convert.ToBoolean(Eval("Revoke")) %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="IsChangedL2GridTemplateColumn" HeaderText="Changed" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:Label ID="IsChangedL2Label" runat="server" Text='<%#Convert.ToBoolean(Eval("IsChanged")) ? "Yes" : "" %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn SortExpression="PreviousAccess" HeaderText="Current Access" DataField="PreviousAccess" UniqueName="PreviousAccessL2GridBoundColumn" HeaderStyle-Width="105px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn HeaderText="Comments" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:ImageButton ID="AddCommentLinkButton" ImageUrl="~/Images/icons/AddComments.png" Width="20px" Height="20px" runat="server" Text="Add Comments" OnClick="AddCommentImageButton_Click" CommandArgument='<%#Eval("L2DetailId") %>' CommandName="EndpointSystemL2Comment"></asp:ImageButton> </ItemTemplate> <HeaderStyle HorizontalAlign="Left" /> </telerik:GridTemplateColumn> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridTemplateColumn Display="false"> <ItemTemplate> <asp:HiddenField ID="HiddenField3" runat="server" Value='<%#Eval("ReviewEndpointId") %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn SortExpression="EndpointUserName" HeaderText="Endpoint User Name" DataField="EndpointUserName" UniqueName="EndpointUserName"> </telerik:GridBoundColumn> <%--<telerik:GridBoundColumn SortExpression="HostName" HeaderText="Endpoint System Name" DataField="HostName" UniqueName="HostName"> </telerik:GridBoundColumn>--%> <telerik:GridBoundColumn SortExpression="DisplayName" HeaderText="Display Name" DataField="DisplayName" UniqueName="DisplayName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="EmployeeType" HeaderText="Employee Type" DataField="EmployeeType" UniqueName="EmployeeType"> </telerik:GridBoundColumn> <telerik:GridBoundColumn SortExpression="EndpointSystemTypeName" HeaderText="Endpoint System Type Name" DataField="EndpointSystemTypeName" UniqueName="EndpointSystemTypeName"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn HeaderText="Approve" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:RadioButton ID="ApproveRadioButton" runat="server" AutoPostBack="true" GroupName="L1" OnCheckedChanged="ApproveRadioButton_CheckedChanged" CssClass="RadGrid_SkinName" Checked='<%#Convert.ToBoolean(Eval("Approve")) %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Revoke" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:RadioButton ID="RevokeRadioButton" runat="server" AutoPostBack="true" GroupName="L1" OnCheckedChanged="RevokeRadioButton_CheckedChanged" CssClass="RadGrid_SkinName" Checked='<%#Convert.ToBoolean(Eval("Revoke"))%>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="IsChangedGridTemplateColumn" HeaderText="Changed" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:Label ID="IsChangedLabel" runat="server" Text='<%#Convert.ToBoolean(Eval("IsChanged")) ? "Yes" : "" %>' /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn SortExpression="PreviousAccess" HeaderText="Current Access" DataField="PreviousAccess" UniqueName="PreviousAccessGridBoundColumn" HeaderStyle-Width="105px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn HeaderText="Comments" HeaderStyle-Width="50px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Right"> <ItemTemplate> <asp:ImageButton ID="AddCommentLinkButton" runat="server" Text="Add Comments" ImageUrl="~/Images/icons/AddComments.png" Width="20px" Height="20px" OnClick="AddCommentImageButton_Click" CommandArgument='<%#Eval("ReviewEndpointId") %>' CommandName="EndpointSystemComment"></asp:ImageButton> </ItemTemplate> <HeaderStyle HorizontalAlign="Left" /> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid> </ContentTemplate> </asp:UpdatePanel></asp:Content> protected void AttestationReviewGrid_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridCommandItem) { Button ibExportToExcel = (e.Item as GridCommandItem).FindControl("bXls") as Button; // ImageButton; ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(ibExportToExcel); Button ibExportToPdf = (e.Item as GridCommandItem).FindControl("bPdf") as Button; // ImageButton; ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(ibExportToPdf); } }protected void AttestationReviewGrid_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == RadGrid.ExportToExcelCommandName) { //AttestationReviewGrid.ExportSettings.HideStructureColumns = false; ////ExpandAll(); //AttestationReviewGrid.Rebind(); //ExpandAll(); AttestationReviewGrid.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client; AttestationReviewGrid.MasterTableView.HierarchyDefaultExpanded = true; AttestationReviewGrid.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true; AttestationReviewGrid.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client; if (AttestationReviewGrid.MasterTableView.DetailTables.Count > 0) // for the second level { AttestationReviewGrid.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true; AttestationReviewGrid.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client; } } }protected void bXls_Click(object sender, EventArgs e) { AttestationReviewGrid.ExportSettings.ExportOnlyData = true; AttestationReviewGrid.ExportSettings.IgnorePaging = true; AttestationReviewGrid.ExportSettings.OpenInNewWindow = true; AttestationReviewGrid.AutoGenerateHierarchy = true; AttestationReviewGrid.MasterTableView.UseAllDataFields = true; AttestationReviewGrid.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML; //AttestationReviewGrid.EnableHierarchyExpandAll = true; AttestationReviewGrid.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client; AttestationReviewGrid.MasterTableView.HierarchyDefaultExpanded = true; // for the first level AttestationReviewGrid.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true; AttestationReviewGrid.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client; if (AttestationReviewGrid.MasterTableView.DetailTables.Count > 0) // for the second level { AttestationReviewGrid.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true; AttestationReviewGrid.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client; } //foreach (GridDataItem item in AttestationReviewGrid.MasterTableView.Items) //{ // item.Expanded = true; //} //AttestationReviewGrid.ExpandedStates[e.Item.ItemIndexHierarchical] = true; AttestationReviewGrid.MasterTableView.ExportToExcel(); //AttestationReviewGrid.MasterTableView.DetailTables[0].ExportToExcel(); }Thanks and Regards,
Balaji
I would recommend that you disable AJAX using the client-side API as explained here:
Export from Ajaxified Grid
Let me know whether this helps.
Regards,
Daniel
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.