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

[Solved] Excel Export Reversing HeaderTemplate of TemplateColumn?

7 Answers 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 21 Nov 2012, 09:51 PM
We have the following template column on one of our grids. When we export to Excel, the three values in the ItemTemplate show up in the right order in Excel, but the three columns of the HeaderTemplate are reversed. Can anyone offer a solution as to why and how to stop this? 

<telerik:GridTemplateColumn UniqueName="TemplateColumn" SortExpression="Approvals"
                        InitializeTemplatesFirst="false">
                        <HeaderTemplate>
                            <table id="tblApproval" cellspacing="0" style="width:100px;" class="myTable">
                                <tr>
                                    <td colspan="3" align="center">
                                        Approved By</td>
                                </tr>
                                <tr>
                                    <td style="width: 33%">
                                        <asp:LinkButton CssClass="Button" ID="btnEmployee" Text="Emp." ToolTip="Sort by Employee Approval"
                                        CommandName='Sort' CommandArgument='EmployeeApproved' runat="server" /></td>
                                    <td style="width: 34%">
                                        <asp:LinkButton CssClass="Button" ID="btnClient" Text="Client" ToolTip="Sort by Client Approval"
                                        CommandName='Sort' CommandArgument='ClientApproved' runat="server" /></td>
                                    <td style="width: 33%">
                                        <asp:LinkButton CssClass="Button" ID="btnPayroll" Text="Acct." ToolTip="Sort by Accounting Approval"
                                        CommandName='Sort' CommandArgument='PayrollApproved' runat="server" /></td>
                                </tr>
                            </table>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table cellspacing="0" width="100%" class="myTable">
                                <tr>
                                    <td style="width: 33%">
                                        <%# ((bool)Eval("EmployeeApproved") == true) ? "Yes" : "No"%>
                                    </td>
                                    <td style="width: 34%">
                                        <%# ((bool)Eval("ClientApproved") == true) ? "Yes" : "No"%>
                                    </td>
                                    <td style="width: 33%">
                                        <%# ((bool)Eval("PayrollApproved") == true) ? "Yes" : "No"%>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridTemplateColumn>

7 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 26 Nov 2012, 05:55 PM
Hello Jonathan,

I am logging this as a bug in our tracking system and our developers will look into it. In the meantime, you can work around it by using html anchor tag(<a>) instead the server link button(asp:LinkButton) in the HeaderItem.
I also updated your Telerik points.

You can track the progress in our Ideas & Feedback Portal.

Kind 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.
0
Jonathan
Top achievements
Rank 1
answered on 04 Jan 2013, 01:52 PM
Kostadin,

Can you give me an example of the hyperlink equivalent of the sort command in the link button? How would I replace the following linkbutton with a hyperlink that did the same thing?

<asp:LinkButton CssClass="Button" ID="btnEmployee" Text="Emp." ToolTip="Sort by Employee Approval"
                                        CommandName='Sort' CommandArgument='EmployeeApproved' runat="server" />
0
Kostadin
Telerik team
answered on 09 Jan 2013, 11:46 AM
Hi Jonathan,

I prepared a small sample where you could see how to use an anchor tag <a> instead the server link button(asp:LinkButton). Give it a try and let me know about the result.

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.
0
Jonathan
Top achievements
Rank 1
answered on 27 Apr 2013, 08:07 PM
Kostadin,

I see the a href tag in use in your sample for the custom Headertemplate, but how do I trigger the appropriate sort from that href?
0
Kostadin
Telerik team
answered on 01 May 2013, 02:23 PM
Hi Jonathan,

A possible solution is to use a client sorting. Another solution is to use both the anchor tags and LinkButtons. When you load the grid you could set display:none to the <a> and when exporting you will disable the LinkButtons control and show the anchor tags.

Greetings,
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.
0
Jonathan
Top achievements
Rank 1
answered on 01 May 2013, 08:48 PM
Hi Kostadin,

I'm attempting replacing the hyperlinks in the ItemDataBound event. Is that the right place or should it be done somewhere else? Below is the code I was attempting for that event. Alternately, if I put another control there in the template, set to invisible, is there a way of doing a FindControl or similar to grab hold of it and turn it on or off during export?

else if (e.CommandName == "ExportToExcel")
            {
                RadGridTimecard.MasterTableView.GetColumn("EditCommandColumn").Visible = false;
 
                //replace linkbuttons with names
                GridTemplateColumn tmpColumn = (GridTemplateColumn)RadGridTimecard.MasterTableView.GetColumn("TemplateColumn");
                //ITemplate hdrItem = tmpColumn.HeaderTemplate;
                StringBuilder sbHeaderTemplate = new StringBuilder();
                sbHeaderTemplate.Append("<table id=\"tblApproval\" cellspacing=\"0\" style=\"width:100px;\" class=\"myTable\">");
                sbHeaderTemplate.Append("<tr>");
                sbHeaderTemplate.Append("<td colspan=\"3\" align=\"center\">");
                sbHeaderTemplate.Append("Approved By</td>");
                sbHeaderTemplate.Append("</tr>");
                sbHeaderTemplate.Append("<tr>");
                sbHeaderTemplate.Append("<td style=\"width: 33%\" valign=\"top\">");
                sbHeaderTemplate.Append("Emp.");
                sbHeaderTemplate.Append("</td>");
                sbHeaderTemplate.Append("<td style=\"width: 34%\">");
                sbHeaderTemplate.Append("Client");
                sbHeaderTemplate.Append("</td>");
                sbHeaderTemplate.Append("<td style=\"width: 33%\">");
                sbHeaderTemplate.Append("Acct.");
                sbHeaderTemplate.Append("</td>");
                sbHeaderTemplate.Append("</tr>");
                sbHeaderTemplate.Append("</table>");
                tmpColumn.HeaderTemplate = null;
                tmpColumn.HeaderText= sbHeaderTemplate.ToString();
                 
                RadGridTimecard.ExportSettings.ExportOnlyData = true;
                RadGridTimecard.ExportSettings.FileName = "Employee Timecard Approval1 " + DateTime.Now.ToString("s");
                RadGridTimecard.MasterTableView.ExportToExcel();
 
            }
0
Kostadin
Telerik team
answered on 07 May 2013, 06:47 AM
Hello Jonathan,

You will be able to access the controls OnItemDataBound event and change their visibility. Additional information of hiding columns and items could be found at the following help article.

Kind 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.
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or