TreeList - Export to Excel/Word




Employee IDLast NameFirst NameTitle Of CourtesyHire DateNotes
12
Page size:
2FullerAndrewDr.8/14/1992 12:00:00 AM
  1DavolioNancyMs.5/1/1992 12:00:00 AM
  3LeverlingJanetMs.4/1/1992 12:00:00 AM

Demo Configurator

DefaultContent
No Skin
Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

This online demo demonstrates the export to Excel feature of the RadTreeList.
The approach is very straightforward - to export the treelist content to Excel format, simply use the ExportToExcel() server-side method. You can configure the exporting settings for the treelist through the RadTreeList.ExportSettings section. Note that the styles applied in the ExportSettings are with bigger priority than the inline styles set for the TreeList. Therefore the exported file will use the styles form the ExportSettings section.

In this demo you could also see the new TreeList CommandItem for built in export buttons

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • scripts.js
<%@ Page Language="C#" CodeFile="~/TreeList/Examples/Export/ExcelExportBasics/DefaultCS.aspx.cs"    Inherits="Telerik.Web.Examples.TreeList.Export.ExcelExportOverview.DefaultCS" %>

<%@ 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>
    <script type="text/javascript" src="scripts.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="demo.onRequestStart" CssClass="demo-container no-bg">
        <br />
        <asp:ImageButton ID="Button1" runat="server" ImageUrl="Images/Excel_BIFF.png"
            OnClick="Button_Click" AlternateText="Biff" />
        <asp:ImageButton ID="Button2" runat="server" ImageUrl="Images/Excel_XLSX.png"
            OnClick="Button_Click" AlternateText="Xlsx" />
        <asp:ImageButton ID="Button3" runat="server" ImageUrl="Images/Word_DOCX.png"
            OnClick="Button_Click" AlternateText="Docx" />
        <br />
        <br />
        <telerik:RadTreeList RenderMode="Lightweight" runat="server" ID="RadTreeList1" OnItemDataBound="RadTreeList1_ItemDataBound"
            AllowPaging="true" PageSize="3" DataKeyNames="EmployeeID" ParentDataKeyNames="ReportsTo" CommandItemDisplay="Top"
            ShowFooter="false" AutoGenerateColumns="false" OnNeedDataSource="RadTreeList1_NeedDataSource">
            <CommandItemSettings ShowExportToExcelButton="true" ShowExportToWordButton="true" />
            <Columns>
                <telerik:TreeListBoundColumn DataField="EmployeeID" UniqueName="EmployeeID" Aggregate="Count"
                    FooterAggregateFormatString="Count: {0}" HeaderText="Employee ID">
                </telerik:TreeListBoundColumn>
                <telerik:TreeListBoundColumn DataField="LastName" UniqueName="LastName" HeaderText="Last Name">
                </telerik:TreeListBoundColumn>
                <telerik:TreeListBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="First Name">
                </telerik:TreeListBoundColumn>
                <telerik:TreeListBoundColumn DataField="TitleOfCourtesy" UniqueName="TitleOfCourtesy"
                    HeaderText="Title Of Courtesy">
                </telerik:TreeListBoundColumn>
                <telerik:TreeListBoundColumn DataField="HireDate" HeaderStyle-Width="180px" UniqueName="HireDate"
                    HeaderText="Hire Date" DataType="System.DateTime">
                </telerik:TreeListBoundColumn>
                <telerik:TreeListTemplateColumn HeaderStyle-Width="280px" HeaderText="Notes">
                    <ItemTemplate>
                        <telerik:RadTextBox RenderMode="Lightweight" ID="RadTextBox1" runat="server" Width="260px" TextMode="MultiLine" Text='<%# Eval("Notes") %>'>
                        </telerik:RadTextBox>
                    </ItemTemplate>
                </telerik:TreeListTemplateColumn>
            </Columns>
        </telerik:RadTreeList>
    </telerik:RadAjaxPanel>
    <qsf:ConfiguratorPanel runat="server" ID="ConfiguratorPanel1" Title="Demo Configurator">
        <Views>
            <qsf:View Title="Export Options">
                <qsf:ConfiguratorColumn ID="ConfiguratorColumn1" runat="server" Size="Narrow">
                    <ul class="fb-group">
                        <li>
                            <span class="checkbox">
                                <asp:CheckBox ID="CB1" runat="server" Text="Ignore paging" Checked="true"></asp:CheckBox></span>
                        </li>
                        <li>
                            <span class="checkbox">
                                <asp:CheckBox ID="CheckBox2" Checked="true" Text="Open in new window" runat="server"></asp:CheckBox></span>
                        </li>
                        <li>
                            <span class="checkbox">
                                <asp:CheckBox ID="CB2" Checked="true" Text="Footer" runat="server"></asp:CheckBox></span>
                        </li>
                    </ul>
                </qsf:ConfiguratorColumn>
                <qsf:ConfiguratorColumn ID="ConfiguratorColumn3" runat="server" Size="Medium">
                    <qsf:DropDownList runat="server" Size="Wide" ID="DDL1">
                        <Items>
                            <telerik:DropDownListItem Value="0" Text="DefaultContent" />
                            <telerik:DropDownListItem Value="1" Text="RemoveControls" />
                            <telerik:DropDownListItem Value="2" Text="ReplaceControls" />
                            <telerik:DropDownListItem Value="3" Text="RemoveAll" />
                        </Items>
                    </qsf:DropDownList>
                </qsf:ConfiguratorColumn>
            </qsf:View>
            <qsf:View Title="Skin Options">
                <qsf:ConfiguratorColumn ID="ConfiguratorColumn2" runat="server" Size="Medium">
                    <label for="DDL2">
                        Choose the skin of the exported file:
                    </label>
                    <qsf:DropDownList runat="server" ID="DDL2" Size="Wide">
                        <Items>
                            <telerik:DropDownListItem Value="0" Text="No Skin" />
                            <telerik:DropDownListItem Value="1" Text="Black" />
                            <telerik:DropDownListItem Value="2" Text="Windows Phone" />
                            <telerik:DropDownListItem Value="3" Text="Colorful" />
                        </Items>
                    </qsf:DropDownList>
                </qsf:ConfiguratorColumn>
            </qsf:View>
        </Views>
    </qsf:ConfiguratorPanel>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance

Help Us Improve

Was this example helpful?