Grid - Word/CSV Export



CustomerIDCompany NameContact NameContact TitleAddressPostal Code
 Item 1 to 10 of 91
Page:
of 10 Page size:
ALFKIAlfreds FutterkisteMaria AndersSales RepresentativeObere Str. 5712209
ANATRAna Trujillo Emparedados y heladosAna TrujilloOwnerAvda. de la Constitución 222205021
ANTONAntonio Moreno TaqueríaAntonio MorenoOwnerMataderos 231205023
AROUTAround the HornThomas HardySales Representative120 Hanover Sq.WA1 1DP
BERGSBerglunds snabbköpChristina BerglundOrder AdministratorBerguvsvägen 8S-958 22
BLAUSBlauer See DelikatessenHanna MoosSales RepresentativeForsterstr. 5768306
BLONPBlondesddsl père et filsFrédérique CiteauxMarketing Manager24, place Kléber67000
BOLIDBólido Comidas preparadasMartín SommerOwnerC/ Araquil, 6728023
BONAPBon app'Laurence LebihanOwner12, rue des Bouchers13008
BOTTMBottom-Dollar MarketsElizabeth LincolnAccounting Manager23 Tsawassen Blvd.T2F 8M4

Demo Configurator

Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB
This example demonstrates RadGrid's Export to Word / CSV formats. There are two ways to integrate the exporting functionality in RadGrid.
  • Codeless (built-in buttons in the CommandItem) - using the CommandItemSettings
  • Manually using the API - we have both server and client methods that can trigger the export

You can configure the exporting settings for the grid through the RadGrid.ExportSettingssection. Most commonly used settings include:

  • FileName - a string specifying the name (without the extension) of the file that will be created. The file extension is automatically added based on the method that is used
  • ExportOnlyData - determines whether only data will be exported
  • IgnorePaging - specifies whether all records will be exported or merely those on the current page
  • OpenInNewWindow - opens the exported grid in a new instead of the same page
  • UseItemStyles - gives you the ability to apply the item styles to the exported file

Note that the exporting feature of the control works with regular postbacks only. Therefore in this demo the new RadAjaxPanel's "PostBackControls" porperty is used for listing the controls that should be excluded from perfoming ajax requests. This property is available for the RadAjaxManager control also sinse Q1 2016 release.

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • scripts.js
  • styles.css
<%@ Page Language="c#" Inherits="Telerik.GridExamplesCSharp.Exporting.ExportToWordCSV.DefaultCS"CodeFile="DefaultCS.aspx.cs"  %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link rel="Stylesheet" type="text/css" href="styles.css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <script type="text/javascript" src="scripts.js"></script>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" PostBackControls="ImageButton1,ImageButton2,ImageButton3" CssClass="demo-container no-bg">
        <asp:ImageButton ID="ImageButton1" ImageUrl="images/file-extension-doc-icon_bigger.png"
            OnClick="Button1_Click" runat="server" CssClass="ImageButtons" />
        <asp:ImageButton ID="ImageButton3" ImageUrl="images/file-extension-docx-icon_bigger.png"
            OnClick="ImageButton3_Click" runat="server" CssClass="ImageButtons" />
        <asp:ImageButton ID="ImageButton2" ImageUrl="images/file-extension-csv-icon_bigger.png"
            OnClick="Button2_Click" runat="server" CssClass="ImageButtons" />
        <br />
        <br />
        <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" DataSourceID="SqlDataSource1" AllowSorting="True" Skin="Silk"
            AutoGenerateColumns="false" AllowPaging="True" PageSize="10" runat="server" OnItemCommand="RadGrid1_ItemCommand">
            <ExportSettings HideStructureColumns="true">
            </ExportSettings>
            <MasterTableView Width="100%" CommandItemDisplay="Top">
                <CommandItemSettings ShowExportToWordButton="true" ShowExportToCsvButton="true" ShowAddNewRecordButton="false" ShowRefreshButton="false" />
                <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
                <Columns>
                    <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID">
                        <HeaderStyle BackColor="#8EDDFF" Font-Bold="true" />
                        <ItemStyle BackColor="#B2F4FF" Font-Italic="true" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CompanyName" HeaderText="Company Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ContactName" HeaderText="Contact Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ContactTitle" HeaderText="Contact Title">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address" HeaderText="Address">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="PostalCode" HeaderText="Postal Code">
                    </telerik:GridBoundColumn>
                </Columns>
                <ItemStyle BackColor="#DFDFDF" />
                <HeaderStyle BackColor="#FFFFFF" ForeColor="#767676" />
                <AlternatingItemStyle BackColor="#FFFFFF" />
            </MasterTableView>
        </telerik:RadGrid>
    </telerik:RadAjaxPanel>
    <qsf:ConfiguratorPanel ID="ConfiguratorPanel2" runat="server">
        <Views>
            <qsf:View>
                <ul class="fb-group">
                    <li>
                        <span class="checkbox">
                            <asp:CheckBox ID="CheckBox1" Text="Export only data" runat="server"></asp:CheckBox></span>
                    </li>
                    <li>
                        <span class="checkbox">
                            <asp:CheckBox ID="CheckBox2" Text="Ignore paging (exports all pages)" runat="server"></asp:CheckBox></span>
                    </li>
                    <li>
                        <span class="checkbox">
                            <asp:CheckBox ID="CheckBox3" Text="Open exported data in new browser window" runat="server"></asp:CheckBox></span>
                    </li>
                    <li>
                        <span class="checkbox">
                            <asp:CheckBox ID="CheckBox4" Text="Use item styles (Word doc-only)" runat="server"></asp:CheckBox></span>
                    </li>
                </ul>
            </qsf:View>
        </Views>
    </qsf:ConfiguratorPanel>
    <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers"
        runat="server"></asp:SqlDataSource>
    </form>
</body>
</html>

Find Assistance

Help Us Improve

Was this example helpful?