Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > BOOK: Beginning ASP.NET Databases
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET Databases Also see the forum ASP Databases for more general discussions of ASP database issues not directly related to these books.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old May 13th, 2009, 08:46 AM
Registered User
Join Date: May 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exporting a dynamically created GridView to Excel

Greetings everyone!

OK, I see many examples out there on how I can export a gridview to Excel. I can even get them to work! It is pretty straight forward. What I need is to be able to export to Excel a GridView created dynamically from a code behind page using VB. My application has many options to the user and the number of columns varies.

Any help and/or guidance would be greatly appreciated.

Thank you,


Here is my code on the .aspx page;

Here is my code on the code behind page (.aspx.vb);
Dim Cols, x AsIntegerDim ColsData AsStringDim gridview1 AsNew GridView
Cols = 0
x = 0
Cols = dtQuery.Columns.Count
DoUntil x >= Cols
ColsData = dtQuery.Columns.Item(x).ColumnName
gridview1.AutoGenerateColumns = FalseDim Field AsNew BoundField
Field.DataField = ColsData
Field.HeaderText = ColsData
Field.HeaderStyle.BackColor = Drawing.ColorTranslator.FromHtml("#0021a5")
Field.HeaderStyle.ForeColor = Drawing.Color.White
Field.HeaderStyle.Font.Name = "Verdana"  Field.HeaderStyle.Font.Size = FontUnit.Small   Field.ItemStyle.Font.Name = "Verdana"  Field.ItemStyle.Font.Size = FontUnit.Small
If x = 0 Then     Field.ItemStyle.BackColor = Drawing.Color.LightGray
Else     Field.ItemStyle.BackColor = Drawing.Color.White
Field.ItemStyle.ForeColor = Drawing.Color.Black
Field.ItemStyle.BackColor = Drawing.Color.White
Dim Col As DataControlField = Field
x = x + 1
gridview1.DataSource = dtQuery
'.... I have tried to bind to an <asp:GridView.... but I cannot get that to export either.......
'.... and the application adds an additional GridView on the aspx page instead of  .........
'.... replacng the one that is there. ............................................................................

Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me about dynamically created controls vingo_mail ASP.NET 2.0 Basics 1 March 24th, 2008 12:54 PM
Exporting gridview into excel yukijocelyn ASP.NET 2.0 Basics 0 September 27th, 2007 10:38 PM
Dynamically created code Puck312 Pro VB 6 3 September 7th, 2005 01:21 PM
how delete objects created dynamically? renee_santoscoi Javascript 1 October 7th, 2004 08:08 PM
Dynamically created controls katsarosj ASP.NET 1.0 and 1.1 Basics 4 February 4th, 2004 08:13 PM

All times are GMT -4. The time now is 06:02 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.