views:

1021

answers:

1

Does anyone have an example (code or a link) that will allow me to export a gridview template field to excel? Here is an example of what I mean. Assume I have the following GridView Declaration:

<asp:GridView Id="gvResults" runat="server">
    <Columns>
        <asp:TemplateField HeaderText="Contact Info">
            <ItemTemplate>
                <b>Name:</b><%# Eval("Name") %><br/>
                <b>Address:</b><%# Eval("Address") %><br/>
                <b>Phone:</b><%# Eval("Phone") %><br/>
                <b>E-mail:</b><%# Eval("Email") %>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

When I export to excel, I want to export the fields in the template field to columns in the excel file, so it will look similar to this:

Name Address Phone E-mail

==== ======= ==== =====

John 123 Rd 40330 [email protected]

Mark 456 St 22039 [email protected]

+1  A: 

I would highly recommend to anyone using out of the box asp gridview controls to consider spending some money on a third party package (DevExpress is my favorite)

That being said, I have used this before when I had no other choice

Matt Briggs
That doesn't seem to help me in exporting a certain part of the ItemTemplate as a column and another part as the value.
Xaisoft