Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to add CSV export from a DataTable (HTML)
Message
De
18/08/2005 14:13:50
 
 
À
18/08/2005 10:19:58
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires Web
Versions des environnements
Environment:
ASP.NET
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01041954
Message ID:
01042034
Vues:
21
Alex,

It's been awhile since I've messed with ASP.NET, but way-back-when when I was playing with it, I would have suggested using SessionState rather than ViewState to persist the DataSet. Someone can correct me if I'm out to lunch, but I think that is still valid advice.

~~Bonnie


>I am tasked to add a CSV export option to an HTML report I have in ASPX.
>Data is in a DataTable and HTML is built manually (more control than with a DataGrid/GridView)
>
>I added a hyperlink to the webpage as follows:
>
>< asp:LinkButton ID="btnExport" runat="server" Width="114px">Export Report< /asp:LinkButton>
>
>What I see is the link when pressed, does a PostBack to he same page. I want to call my ExportDataToCSV() below:
>
>public bool ExportDataToCSV(DataTable oSourceTable, string sFileName, string sDelimiter, Boolean IsWriteColumnHeaders)
>{
>  // TODO: loop through rows and columns creating delimited strings
>  // then send to the client through HTTP
>}
>
>Questions: Is there a better way to do this than through a Postback?
>If a Postback,
>a. how do I pass the DataTable to the method call? (as ViewState is kinda wasteful and would have to be cast a DataTable - how do I do that?)
>b. if DataTable is passed directly as a parameter (better than through HTTP IMO), how do I accomplish that from the LinkButton?
>
>Hope I'm clear enough. Now back to battling with C# <g>
>
>[UPDATE]: as I'm already looping through the DataSet when building an HTML table I could also build a CSV at the same time then pass it as a string and avoid passing a DataSet (makes it easier through PostBack?).
>Drawbacks: It might be a large string. It is extra work done every time when they may only want to download a CSV copy of the HTML table every so often.
>
>Thoughts?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform