.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 20th, 2004, 03:42 AM
iluder iluder is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 1 iluder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Little Bug in ASP.NET, cannot export to excel well...Please Help, urgent!

Hi all,

I've been posting a lot of forums, about this problem, and until now, i didn't get any solution.

The problem is this, i've got to get the values of a table, created dynamicly, by pressing a button, from a sql query.
Here's the code, that will demosntrate my problem for you can test itC#, ASP.NET)
Code:
ASPX File 
__________________________________________________  ________________________________ 

<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="Smyle.WebForm2" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<HTML> 
<HEAD> 
<title>WebForm2</title> 
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> 
<meta name="CODE_LANGUAGE" Content="C#"> 
<meta name="vs_defaultClientScript" content="JavaScript"> 
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> 
</HEAD> 
<body MS_POSITIONING="GridLayout"> 
<form id="WebForm2" method="post" runat="server"> 
<asp:Table id="DisplayTable" style="Z-INDEX: 101; LEFT: 160px; POSITION: absolute; TOP: 160px" runat="server" Width="512px" Height="32px"></asp:Table> 
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 376px; POSITION: absolute; TOP: 216px" runat="server" Text="Excel export"></asp:Button> 
<asp:Button id="Button2" style="Z-INDEX: 103; LEFT: 296px; POSITION: absolute; TOP: 216px" runat="server" Text="Fill Table"></asp:Button> 
</form> 
</body> 
</HTML> 


__________________________________________________  ________________________________ 

CodeBehind File 
__________________________________________________  ________________________________ 

using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Web; 
using System.Web.SessionState; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.HtmlControls; 
using System.IO; 
using System.Data.SqlClient; 

namespace Smyle 
{ 
/// <summary> 
/// Summary description for WebForm2. 
/// </summary> 
public class WebForm2 : System.Web.UI.Page 
{ 
#region//variaveis 
TableRow tableHeading = new TableRow(); 
//variaveis de acesso á base de dados 
string sql; 
public SqlConnection bdconn; 
public SqlCommand bdcomm; 
public SqlDataReader bdreader; 
#endregion 
protected System.Web.UI.WebControls.Button Button1; 
protected System.Web.UI.WebControls.Button Button2; 
protected System.Web.UI.WebControls.Table DisplayTable; 

private void Page_Load(object sender, System.EventArgs e) 
{ 
// Put user code to initialize the page here 
Response.Buffer=true; 
Response.Clear(); 
Response.Charset = ""; 
bdconn = new SqlConnection("User ID=****;Password=****;Persist Security Info=False;Initial Catalog=Smyle;Data Source="+ Servidor.***() +""); 
bdconn.Open(); 
if(!Page.IsPostBack) 
{ 

}             
TableHeaderCell Descricao = new TableHeaderCell(); 
Descricao.Text = "Descrição de Usage"; 
Descricao.HorizontalAlign = HorizontalAlign.Left; 
tableHeading.Cells.Add(Descricao); 
DisplayTable.Rows.Add(tableHeading); 

TableRow TableRow = new TableRow(); 
TableCell UsagDescri = new TableCell(); 
UsagDescri.Text ="teste"; 
TableRow.Cells.Add(UsagDescri); 

DisplayTable.Rows.Add(TableRow); 
} 

#region Web Form Designer generated code 
override protected void OnInit(EventArgs e) 
{ 
// 
// CODEGEN: This call is required by the ASP.NET Web Form Designer. 
// 
InitializeComponent(); 
base.OnInit(e); 
} 

/// <summary> 
/// Required method for Designer support - do not modify 
/// the contents of this method with the code editor. 
/// </summary> 
private void InitializeComponent() 
{     
this.Button1.Click += new System.EventHandler(this.Button1_Click); 
this.Button2.Click += new System.EventHandler(this.Button2_Click); 
this.Load += new System.EventHandler(this.Page_Load); 

} 
#endregion 

private void Button1_Click(object sender, System.EventArgs e) 
{ 
Response.Clear(); 
Response.Buffer=true; 
//Response.Charset = ""; 
Response.ContentType = "application/vnd.ms-excel"; 
System.IO.StringWriter stwWriter = new System.IO.StringWriter(); 
System.Web.UI.HtmlTextWriter htwHtmlTextWriter = new System.Web.UI.HtmlTextWriter(stwWriter) ; 
DisplayTable.RenderControl(htwHtmlTextWriter); 
Response.Write(stwWriter.ToString()); 
Response.End(); 
} 
private void Button2_Click(object sender, System.EventArgs e) 
{ 
sql="Select descricao from usage"; 
bdcomm=new SqlCommand(sql,bdconn); 
bdreader=bdcomm.ExecuteReader(); 
while(bdreader.Read()) 
{ 
TableRow TableRow = new TableRow(); 
TableCell UsagDescri = new TableCell(); 
UsagDescri.Text =bdreader["Descricao"].ToString(); 
TableRow.Cells.Add(UsagDescri); 

DisplayTable.Rows.Add(TableRow); 
} 
bdreader.Close(); 
bdconn.Close(); 
} 
} 
} 
I know that this could be boring, but it's a litle bug in ASP.NET, that could appear to any one. Thanks, i will wait for you help, in front of the screen.

Thanks

Reply With Quote
  #2  
Old January 30th, 2004, 08:52 AM
hammerman hammerman is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 9 hammerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well...

I did'nt look at all that code you have.. but I'm curious how are you trying to generate and excel file. I have used an com ojbect (that will work in .net) call aspspeedgen - it creates native excel spreasheets and streams to the browser or to disk. its super simple and fast - bind your dataset directly to it.. look at http://www.excelspeedgen.com/

Reply With Quote
  #3  
Old March 16th, 2004, 05:28 AM
pparasnis pparasnis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 pparasnis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

As you create the rows and the column throught the HtmlTable Row and html Table Column then
If you know the columns that are going to export then for the Export functionalty you have to mention all the coumns
that has to be Exported.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Litle Bug in ASP.NET, cannot export to excel well...Please Help, urgent!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT