Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2005, 04:47 AM
PT PT is offline
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exporting Data from DataGrid to a CSV file

I have no clue how to do that, can someone tell some hints?

/PT

 
Old June 20th, 2005, 08:00 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There isn't a direct way to do this as the DataGrid is designed as an HTML targeted control. You can however build up a CSV structure from the data source of the grid.

-Peter
 
Old June 22nd, 2005, 04:41 AM
PT PT is offline
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the code to export data from grid to xls. But the problem is when the grid has more than one page the file cant be exported.

Code:

YourDataGrid.Columns[0].Visible = false; //This hides the line where the ButtonCollumn is.
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
YourDataGrid.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
YourDataGrid.Columns[0].Visible = true;

Error:

Control 'UCClientes_YourDataGrid__ctl21__ctl1' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'UCClientes_YourDataGrid__ctl21__ctl1' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.

Source Error:


Line 138:
Line 139:
Line 140: Dt.RenderControl(oHtmlTextWriter);
Line 141:
Line 142:





Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data from datagrid to excel??? twyce C# 3 March 4th, 2010 04:51 AM
Exporting a csv file (comma separated) micharl Beginning VB 6 6 May 7th, 2008 10:10 PM
Exporting a Datagrid to a CSV file pauljohns353 Visual Basic 2005 Basics 1 November 21st, 2006 04:56 PM
Exporting a DataGrid to a CSV - VB.net pauljohns353 Visual Studio 2005 0 October 19th, 2006 08:46 AM
Need help in exporting memo fields to CSV file Programming_starter C# 0 May 22nd, 2006 11:25 AM





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