RadGrid Export Excel "HeaderText" field as Column Name

4 posts, 0 answers
  1. nagendra
    nagendra avatar
    34 posts
    Member since:
    Jan 2009

    Posted 19 Nov 2011 Link to this post

    Hi All,

    I have radgrid. I have some columns which have HeaderText is different from that of DataFeild column. When i do ExporttoExcel i need to export the HeaderText Column name as First row in the column.
    <telerik:GridTemplateColumn DataField="ErrorText" HeaderButtonType="TextButton" HeaderText="Poster Response"
                                                   UniqueName="ErrorText" Visible="true"  SortExpression="ErrorText">
                                                   <HeaderStyle HorizontalAlign="left" Width="135px" />
                                                   <ItemStyle HorizontalAlign="left" />
                                                   <ItemTemplate>
                                                       <asp:Label ID="lblErrorText" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ErrorText")%>'>
                                                       </asp:Label>
                                                   </ItemTemplate>
                                               </telerik:GridTemplateColumn>
    Even i want to export only Visible Columns. For Example in this column i have ErrorText as DataField , Poster Response as HeaderText when i export to excel i want the Poster Response as Column name in Excel instead of ErrorText. Please let me know the solution.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 20 Nov 2011 Link to this post

    Hello,

    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid2_NeedDataSource">
                <ExportSettings ExportOnlyData="true"></ExportSettings>
                <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top">
                    <CommandItemSettings  ShowExportToExcelButton="true" />
                    <Columns>
                        <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn DataField="Name" HeaderButtonType="TextButton" HeaderText="Poster Response"
                            UniqueName="ErrorText" Visible="true" SortExpression="ErrorText">
                            <HeaderStyle HorizontalAlign="left" Width="135px" />
                            <ItemStyle HorizontalAlign="left" />
                            <ItemTemplate>
                                <asp:Label ID="lblErrorText" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name")%>'>
                                </asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>

    protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
           {
               
     
               dynamic data = new[] {
                   new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                    new { ID = 1, Name ="name1"},
                   new { ID = 2, Name = "Name2"},
                   new { ID = 3, Name = "name3"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 4, Name = "Name4"},
                   new { ID = 5, Name = "name5"}
               };
               RadGrid2.DataSource = data;
     
           }

    I am not able to reproduce the issue.
    Please check above code snippet and i also attached file.

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Spiros
    Spiros avatar
    15 posts
    Member since:
    May 2010

    Posted 18 Sep 2014 in reply to Jayesh Goyani Link to this post

    Hi Jayesh .
    How I can export the  RadGrid1.MasterTableView.Caption = "&&&&&"
    in Master Detail Grid .
    Thanks

  5. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 22 Sep 2014 Link to this post

    Hi Spiros,

    I answered your question in the following forum thread, so if you have more questions I would recommend you to continue there and close this one.

    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.

     
Back to Top