This is a migrated thread and some comments may be shown as answers.

RadGrid Export Excel "HeaderText" field as Column Name

3 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
nagendra
Top achievements
Rank 1
nagendra asked on 20 Nov 2011, 04:11 AM
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.

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Nov 2011, 08:21 AM
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
0
Spiros
Top achievements
Rank 1
answered on 18 Sep 2014, 06:14 AM
Hi Jayesh .
How I can export the  RadGrid1.MasterTableView.Caption = "&&&&&"
in Master Detail Grid .
Thanks

0
Kostadin
Telerik team
answered on 22 Sep 2014, 02:33 PM
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.

 
Tags
Grid
Asked by
nagendra
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Spiros
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or