C# .NET - When exporting from gridview to excel template column labels fail

Asked By Mike Bartley on 16-Jun-16 07:25 PM

When I export to Excel any template column with a label control is blank.  If I change the template column to a bound field it will work but it not always an option as I have to deal with compound data labels.


<Columns>

<asp:TemplateField HeaderText="Region">

<ItemTemplate>

<asp:Label ID="lblRegion" runat="server" Text='<%#Eval("Region") %>' Visible="false"/>

</ItemTemplate>

<FooterTemplate>

<asp:Label ID="lblFooterRegion" runat="server" Text="Total" />

</FooterTemplate>

<ItemStyle HorizontalAlign="Center" Width="25%" />

</asp:TemplateField>

<asp:TemplateField HeaderText="Inventory $">

<ItemTemplate>

<asp:Label ID="lblBalance" runat="server" Text='<%# string.Format("{0:C}", Eval("Balance")) %>'/>

</ItemTemplate>

<FooterTemplate>

<asp:Label ID="lblFooterBalance" runat="server" />

</FooterTemplate>

<ItemStyle HorizontalAlign="Center" Width="25%" />

</asp:TemplateField>