We have several pages where we have successfully exported RadGrid contents to Excel using the ExportToExcel() method. However, we now have a situation where we have a multi-page wizard using a MultiView controls and one of the View controls has a RadGrid on it with a preview of some results. The users would like to be able to export this RadGrid to Excel. However, the typical code does not work:
protected void ExportToExcelButton_Click(object sender, EventArgs e)
{
PreviewGrid.ExportSettings.IgnorePaging = true;
PreviewGrid.ExportSettings.OpenInNewWindow = true;
PreviewGrid.MasterTableView.ExportToExcel();
}
The RadGrid is fairly simple:
<telerik:RadGrid ID="PreviewGrid" AutoGenerateColumns="False"
OnNeedDataSource="PreviewGrid_NeedDataSource"
runat="server" Width="730px" Height="362px">
<ClientSettings>
<Selecting EnableDragToSelectRows="false"/>
<Scrolling AllowScroll="true" UseStaticHeaders="True"></Scrolling>
</ClientSettings>
<MasterTableView DataKeyNames="Key" NoMasterRecordsText="Nothing would be generated." CommandItemDisplay="Top" >
<CommandItemTemplate>
<div class="floatRightDiv" style="margin-top: 3px;margin-left: 700px;display:none;">
<asp:Button ID="ExportToExcelButton" runat="server" CssClass="rgExpXLS" OnClick="ExportToExcelButton_Click" Visible="false"/>
</div>
</CommandItemTemplate>
<Columns>
<telerik:GridBoundColumn UniqueName="Field1" DataField="Field1" HeaderText="Field1"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Field2" DataField="Field2" HeaderText="Field2"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Field3" DataField="Field3" HeaderText="Field3"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Field4" DataField="Field4" HeaderText="Field4"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Field5" DataField="Field5" HeaderText="Field5"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Amount" DataField="Amount" HeaderText="Amount" DataFormatString="{0:N2}" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
How can we export from a grid in a window?