Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 December 14th, 2004, 01:32 PM
Authorized User
 
Join Date: Dec 2004
Location: Mexico City, , Mexico.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default Export data from a datalist to an Excel sheet

I’m using this code to export data from a datagrid to an Excel sheet:



Response.Clear();

Response.Buffer= true;

Response.ContentType = "application/vnd.ms-excel";

Response.AddHeader("Content-Disposition", "inline;filename=Clientes.xls");

Response.Charset = "";

this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();



And this is working fine.

But now I want to do same with a datalist and thus I changed RenderControl line thus:



DataList1.RenderControl(oHtmlTextWriter);



Yet when Excel sheet is showing on screen, all data are displayed in one simple column “A”, with one row for each data in datalist.



Does somebody know how can I attain it work as I did as datagrd (each column in datalist into its respective column in Excel)?



I’ll appreciate your suggestions.



A.L.

:D

El Hombre que tiene Amigos ha de mostrarse Amigo
__________________
El Hombre que tiene Amigos ha de mostrarse Amigo
  #2 (permalink)  
Old February 23rd, 2007, 05:55 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Has anyone figured out how to do this?

  #3 (permalink)  
Old February 23rd, 2007, 06:29 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

A datalist is like a repeater (more or less) where you can format you data any which way you choose which may not necessarily be in a table format. (Rows/columns)

A datalist uses the ItemTemplate, however, not the TemplateColumn tag the datagrid control on the other hand, does. By design a datagrid exports to excel fine because it has its rows and columns defined.

What you may want to do is when you go to export your data, take your datalist Datasource and bind it to an in memory datagrid, then export that datagrid to excel. I think it would work out better for you.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
  #4 (permalink)  
Old February 23rd, 2007, 07:20 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

This would work great if I wanted the actual data that was returned from the data source, but I actually tweak the values being returned and then post to the datalist.

For example, I am pulling back from my query a "totalSumMinutes" value...in my DataList, however, my binding is personalized to go through a personalized function that has two methods:

<datalist>
<itemtemplate>
<div style="float:left; width:40px"><asp:Label ID="Label6" runat="server" Text='<%# EventStruct.CalculateHours(Eval("total")) %>'></asp:Label></div>

<div style="float:left; width:40px"><asp:Label ID="Label1" runat="server" Text='<%# EventStruct.CalculateMinutes(Eval("total")) %>' ></asp:Label> </div>

..where the methods are below:

Public Shared Function CalculateHours(ByVal total As Object) As Integer
        Dim returnInt As Integer = 0
        If total IsNot DBNull.Value Then
            returnInt = (total / 60) - 0.5
        End If
        Return returnInt
    End Function

    Public Shared Function CalculateMinutes(ByVal total As Object) As Integer
        Dim returnInt As Integer = 0
        If total IsNot DBNull.Value Then
            returnInt = total Mod 60
        End If
        Return returnInt
    End Function

So, you can see, that simply setting the Datagrid's datasource will not give me the output I need.

I actually need to figure out how to render the datalist somehow.

Regards,
Rob
 


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
Export Values to Excel Sheet from Sub form ayazhoda Access VBA 3 June 12th, 2012 03:18 PM
Gridview data export to excel sheet abhishekkashyap27 C# 2005 1 August 1st, 2008 10:10 AM
Export DataList to Excel rsearing ASP.NET 2.0 Professional 0 February 23rd, 2007 03:31 PM
How To Export a specific Excel Sheet as a csv file mrjits Excel VBA 5 August 1st, 2006 03:04 PM
Export Image to Excel sheet haribala.raj General .NET 0 September 13th, 2005 11:56 PM



All times are GMT -4. The time now is 03:05 PM.


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