Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional 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 Search this Thread Display Modes
  #1 (permalink)  
Old March 29th, 2005, 11:57 AM
Registered User
Join Date: Mar 2005
Location: Orlando, FL, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem exporting datagrid to excel

I am trying to send the contents of a datagrid to excel using C#. The code is as follows:

private void exportButton_Click(object sender, System.EventArgs e)
            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.Charset = "";
            this.EnableViewState = false;
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            hw.RenderBeginTag(System.Web.UI.HtmlTextWriterTag. Html);

        private void ClearControls(Control control)
            for (int i=control.Controls.Count -1; i>=0; i--)

            if (!(control is TableCell))
                if (control.GetType().GetProperty("SelectedItem") != null)
                    LiteralControl literal = new LiteralControl();
                        literal.Text = (string)control.GetType().GetProperty("SelectedIte m").GetValue(control,null);
                    if (control.GetType().GetProperty("Text") != null)
                    LiteralControl literal = new LiteralControl();
                    literal.Text = (string)control.GetType().GetProperty("Text").GetV alue(control,null);

When running the code only the first column appears in the spreadsheet. What do I need to do to fix this problem?


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Problem in exporting data from datagrid to Excel deb_kareng ASP.NET 2.0 Professional 4 August 4th, 2007 09:21 AM
exporting to excel from datagrid hotshot_21 ASP.NET 1.0 and 1.1 Basics 2 June 9th, 2006 08:53 AM
problem in exporting datagrid to excel swati_joshi ASP.NET 1.0 and 1.1 Professional 3 June 4th, 2006 11:26 PM
Exporting data to excel from datagrid, Problem. swadhinm ASP.NET 1.x and 2.0 Application Design 0 May 31st, 2005 01:44 AM
Exporting DataGrid To Excel chiefg C# 2 December 31st, 2003 12:23 PM

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

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