Fix for exporting values in template columns to Excel for Telerik Radgrid

While exporting to excel for Telerik Radgird we always come up with the problem that values in template columns won’t get uploaded to excel.

I have googled for the same and got different answers. But nothing worked for me.

Then I looked into different options on my own and found an easy way to do the same

<telerik:GridTemplateColumn DataField=”materialQty” AllowFiltering=”false” HeaderText=”Total” HeaderStyle-Width=”9%”>
<asp:LinkButton ID=”materialQty” runat=”server” Text='<%# Eval(“materialQty”)%>’ CssClass=”contentBoldLink”
ToolTip=”Engineered Qty(Draft) Breakup”></asp:LinkButton>

<span style=”display:none;”><%# Eval(“materialQty”)%></span><!– for display in export to excel only–>

<ItemStyle HorizontalAlign=”Right” />

Please see the code in bold. I have created a span element with its display as none and bound the same materialQty value.

So what it does is upon export to excel, it will not export the html tags but only the bounded value

And here is the code for exporting the data…

RadMTO.ExportSettings.ExportOnlyData = True
RadMTO.ExportSettings.IgnorePaging = True
RadMTO.ExportSettings.OpenInNewWindow = True
RadMTO.ExportSettings.FileName = “MTO”

Happy programming all 🙂


3 Comments Add yours

  1. Right on! Just what I needed.

  2. Claus says:

    When I use this solution, I get the span-tag in the exported Excel-file. What am I missing?

  3. vishnukj says:

    style=”display:none;” would be missing

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s