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 J@j.com
Mark 456 St 22039 M@M.com
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