473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Can't render Gridview

ad
I use the codes below to render a Gridview to Excel.
But it fail with
RegisterForEventValidation can just be call in Render()

But if myGrid is a DataGrid, it run well.

How can I render a GridView to Excel?
----------------------------------------------------------------------------------------
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

May 7 '06 #1
1 2125
This will not work. The reason being is that the Excel file format is
not HTML, which is what you are writing.

You would have to save the HTML, or write XML in the format that Excel
expects (I believe Office 2003 supports sheets in an XML format now).

Or, you could find a third party component that allows you to write XLS
files. I wouldn't advise automating Excel in a web environment.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
I use the codes below to render a Gridview to Excel.
But it fail with
RegisterForEventValidation can just be call in Render()

But if myGrid is a DataGrid, it run well.

How can I render a GridView to Excel?
----------------------------------------------------------------------------------------
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

May 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ABC | last post by:
I have an idea. I need to write a common gridview block which contains labels, textboxs, one girdview and some buttons. Then, I think the above block will apply on several girdview with...
0
by: John | last post by:
I'm trying to override the page's render method, and capture the result for processing, eg: protected override void Render(HtmlTextWriter writer) { //base.Render(writer); StringBuilder...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
3
by: wind | last post by:
i use the code in exporting gridview to excel and and work just fine but when i adjust it to my implementation of a search record I'm getting the said error (registerforeventvalidation can only be...
0
by: bingunginter | last post by:
I am using SQL 2005 server database. In my table I had fields that has chinese character (nvarchar type) and html tag <b></b>. I retrieve the table and display it in gridview. It displays the...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
2
by: Jason | last post by:
Hi all, I hope this doesn't sound like a lame question, but I want to override Gridview.Render so I can strip out ALL styling elements and use CSS for my styling. I am pretty sure I can figure it...
0
by: Jeff | last post by:
hey asp.net 3.5 I have 2 UpdatePanels in my webpage. This webpage has a GridView, which one of its column is a templatefield which again contain a UpdatePanel and a button... The other...
5
by: Eric | last post by:
Hi, there are several gridviews all with a linkbutton which all trigger the same procedure. I need to know from which gridview the linkbutton has been clicked. Thanks Eric Here the code:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.