Problem with Export to Excel with template columns data not displaying.

9 posts, 0 answers
  1. shaik
    shaik avatar
    15 posts
    Member since:
    Dec 2007

    Posted 05 Mar 2009 Link to this post

    Hi,
    Hi,
    We have implemented template columns in the telerik grid
    We are tryig to use export to excel functionallity, which works great, except that it doesn't export data in the template columns. The columns are in the Excel, but they are all empty.

    ASPX Code As folows:

    <

    telerik:GridHyperLinkColumn UniqueName="IH_LOG_NUMBER" DataTextField="IH_LOG_NUMBER"

     

     

    HeaderText="<%$ Resources:Multilingual, IHLogNumber %>">

     

     

    </telerik:GridHyperLinkColumn>

     

     

    <telerik:GridBoundColumn Visible="false" UniqueName="IH_LOG_Exp" DataField="IH_LOG_NUMBER"

     

     

    HeaderText="<%$ Resources:Multilingual, IHLogNumber %>">

     

     

    </telerik:GridBoundColumn>

     


     

     

     

    <telerik:GridTemplateColumn AllowFiltering="False" UniqueName="Comments" HeaderText="<%$ Resources:Multilingual, Comments %>" >

     

     

     

     

     

    <ItemTemplate>

     

     

     

     

     

    <asp:DropDownList ID="ddlComments" CssClass="DDDW" AppendDataBoundItems="true" runat="server"

     

     

     

     

     

    SelectedValue='<%# Bind("COMMENT_ID") %>' DataSourceID="SqlDataSource1" DataTextField="COMMENT_NAME"

     

     

     

     

     

    DataValueField="COMMENT_ID" Style="width: 100px;">

     

     

     

     

     

    <asp:ListItem Value="0" Text="Please Select" Selected="True"></asp:ListItem>

     

     

     

     

     

    </asp:DropDownList>

     

     

     

     

     

    </ItemTemplate>

     

     

     

     

     

    <HeaderStyle Width="100px" />

     

     

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

    <telerik:GridTemplateColumn HeaderText="<%$ Resources:Multilingual, ApprovedInvalidateDate %>" AllowFiltering="False"

     

     

    UniqueName="SAMPLE_VALIDATED_DATE">

     

     

    <ItemTemplate>

     

     

    <telerik:RadDatePicker ID="rdpSampleDate" DbSelectedDate='<%# Bind("SAMPLE_VALIDATED_DATE", "{0:d}") %>'

     

     

    runat="server" >

     

     

     

    </telerik:RadDatePicker>

     

     

    </ItemTemplate>

     

     

    <HeaderStyle Width="130px" />

     

     

    <ItemStyle Wrap="True" />

     

     

    </telerik:GridTemplateColumn>

     

    Below are the lines of code that export to Excel:

    private

    void ConfigureExport()

     

    {

    rGrdSampleList.MasterTableView.GetColumn(

    "ClientSelectColumn").Visible = false;

     

    rGrdSampleList.MasterTableView.GetColumn(

    "EQUIPMENT_ID").Visible = false;

     

    rGrdSampleList.MasterTableView.GetColumn(

    "IH_LOG_NUMBER").Visible = false;

     

    rGrdSampleList.MasterTableView.GetColumn(

    "IH_LOG_Exp").Visible = true;

     

    rGrdSampleList.MasterTableView.Columns.FindByUniqueName("Comments").Visible = true; rGrdSampleList.MasterTableView.Columns.FindByUniqueName(

    "SAMPLE_VALIDATED_DATE").Visible = true;

     

    rGrdSampleList.ExportSettings.ExportOnlyData =

    true;

     

    rGrdSampleList.ExportSettings.OpenInNewWindow =

    true;

     

     

    //rGrdSampleList.ExportSettings.IgnorePaging = true;

     

    }

     

    protected void RadMenu1_ItemClick1(object sender, RadMenuEventArgs e)

     

    {

     

    try

     

    {

    ConfigureExport();

     

    if (e.Item.Text == Resources.Multilingual.Word)

     

    {

     

    //MsgBox"1")

     

    rGrdSampleList.MasterTableView.ExportToWord();

    }

     

    else if (e.Item.Text == Resources.Multilingual.Excel)

     

    {

     

    //MsgBox"2")

     

    rGrdSampleList.MasterTableView.ExportToExcel();

    }

     

    else if (e.Item.Text == Resources.Multilingual.Pdf)

     

    {

    rGrdSampleList.MasterTableView.ExportToPdf();

    }

    }

     

    catch (Exception exe)

     

    {

    exe.ToString();

    }

    }

    Is this by design or are there workarounds?
    I'm Waiting for reply as soon as possible

    Thanks.


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Mar 2009 Link to this post

    Hi,

    Since GridTemplateColumn is having controls inside the ItemTemplate they are not considered as data, that is why when you select the second parameter of the ExportToExcel method to be true, those controls will be stripped from the resulting Excel file. You can refer the following help article to get more details regarding this.

    Go through the portion:

    Exporting GridButtonColumn/GridTemplateColumn/GridHyperLinkColumn data

    Exporting tips and tricks

    Thanks
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kanchan
    Kanchan avatar
    8 posts
    Member since:
    Aug 2012

    Posted 24 Aug 2012 Link to this post

    Any one can please provide the code of above problem(Export to Excel with template columns data not displaying.)
  5. Kanchan
    Kanchan avatar
    8 posts
    Member since:
    Aug 2012

    Posted 24 Aug 2012 Link to this post

    Shinu , can you please provide us the code for problem Export to Excel with template columns data not displaying.
  6. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 29 Aug 2012 Link to this post

    Hello Kanchan,

    As the template columns are not exported by default, you have to implement it by yourself. I attached a simple project that demonstrates how to achieve this.

    Regards,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Karu
    Karu avatar
    3 posts
    Member since:
    Feb 2012

    Posted 30 Jun 2014 in reply to Shinu Link to this post

     <telerik:GridTemplateColumn AllowFiltering="false" HeaderText="Date" UniqueName="R_Date" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="Small">
                                    <ItemTemplate>
                                        <telerik:RadDatePicker ID="RadDatePicker1" runat="server" Width="100px" DatePopupButton-Visible="false"
                                            ShowPopupOnFocus="true" DbSelectedDate='<%# Bind("R_Date") %>'>
                                            <DateInput ID="DateInput1" runat="server" DateFormat="MM/dd/yyyy" onkeydown="keyDown(this, event)">
                                            </DateInput>
                                        </telerik:RadDatePicker>                                    
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn> I am using Telerik Rad datepicker to showin the grid . thats working fine. But problem is - Export to PDF am not able to get the DatePicker value. 
  8. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 03 Jul 2014 Link to this post

    Hi Karu,

    I am afraid exporting of DatePicker control to PDF is not supported. Nevertheless you could add a Label controls in the ItemTemplate which is initially hidden. When you perform an export to PDF command you will show the Label and the text will be exported.

    Regards,
    Kostadin
    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.

     
  9. khurram
    khurram avatar
    1 posts
    Member since:
    May 2016

    Posted 04 May Link to this post

    hi, i have a telerik:RadGrid, in which i have gridbound column and  grid template column , i want to export that data in excel, everything is fine but grid template column shows blank in excel file... why i use grid template column with gridbound column ? because i was wanting to add scroll bar into column cell{multiline text}, which was not availabe with gridbound.

     

                          <telerik:RadGrid ID="GV_RequestDetail" runat="server" AllowFilteringByColumn="True"
                    AllowSorting="True" AutoGenerateColumns="False" CellSpacing="0" GridLines="Horizontal"
                    PageSize="5" autopostbackonfilter="True" OnExcelMLExportStylesCreated="GV_SO_ExcelMLExportStylesCreated" OnExcelMLExportRowCreated="GV_RequestDetail_ExcelMLExportRowCreated"
                    Width="100%" OnNeedDataSource="GV_RequestDetail_NeedDataSource" Skin="Transparent"
                    OnItemDataBound="GV_RequestDetail_ItemDataBound" >
                    <GroupingSettings CaseSensitive="false" />
                    <ExportSettings ExportOnlyData="true" IgnorePaging="true" FileName="RequestDetailReport">
                    </ExportSettings>
                    <ClientSettings >
                        <Scrolling  AllowScroll="True" UseStaticHeaders="true"  />
                    </ClientSettings>
                    <PagerStyle Mode="NextPrevAndNumeric" />
                    <MasterTableView  ShowFooter="True" CommandItemDisplay="Top"  CommandItemSettings-ShowRefreshButton="false"
                        CommandItemSettings-ShowAddNewRecordButton="false" PageSize="20" AllowPaging="True"                              CommandItemSettings-ShowExportToExcelButton="true" CommandItemSettings-ShowExportToWordButton="true">
                        <CommandItemSettings   ExportToPdfText="Export to PDF" />
                        <RowIndicatorColumn   FilterControlAltText="Filter RowIndicator column" Visible="True">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn  FilterControlAltText="Filter ExpandColumn column" Visible="True">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            
                            <telerik:GridBoundColumn AutoPostBackOnFilter="True" DataField="priority_description"
                                FilterControlAltText="Filter priority_description column" HeaderText="Priority"
                                UniqueName="priority_description">
                                <HeaderStyle Width="120px" />
                                <ItemStyle Width="120px" />
                            </telerik:GridBoundColumn>
                          
           


                            <telerik:GridTemplateColumn HeaderText="Issue Description" AutoPostBackOnFilter="false" UniqueName="abc">
                                <ItemTemplate >
                                    <telerik:RadTextBox ID="txtProblemDescription" runat="server" LabelWidth="" Rows="3"
                                        Text='<%# Bind("problem_description") %>' Width="200px" TextMode="MultiLine"
                                        ReadOnly="true" >
                                        </telerik:RadTextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="225px" />
                                <ItemStyle Width="225px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="sub_dte" FilterControlAltText="Filter sub_dte column"
                                HeaderText="Submission Date" SortExpression="sub_dte" UniqueName="sub_dte" AutoPostBackOnFilter="True" ItemStyle-CssClass="problem_description">
                                <HeaderStyle Width="120px" />
                                <ItemStyle Width="120px" />
                            </telerik:GridBoundColumn>
                           
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <HeaderStyle Width="150px" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>

  10. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 09 May Link to this post

    Hello Khurram,

    In order to export the content of the template column you can disable the paging in code behind and rebind the grid instead using IgnorePaging property. Please check out the following code snippet.
    protected void GV_RequestDetail_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToExcelCommandName)
        {
            GV_RequestDetail.MasterTableView.AllowPaging = false;
            GV_RequestDetail.Rebind();
        }
    }


    Regards,
    Kostadin
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017