Title:
excellent post
Name:
shivani
Date:
2012-08-09 1:38:51 AM
Comment:
thanks alot... it really helped me.. :)
|
Title:
asd
Name:
dd
Date:
2012-04-26 11:32:10 AM
Comment:
dsddad
|
Title:
Asp.net Grid view to excel
Name:
Devendra rai
Date:
2012-04-11 6:16:26 AM
Comment:
Excellent Post
|
Title:
ASP.net grid view to export excel
Name:
Susan
Date:
2012-03-22 12:33:38 PM
Comment:
code is not executing
|
Title:
ASP.net grid view to export excel
Name:
Tharani
Date:
2011-08-23 7:28:46 AM
Comment:
http://aspalliance.com/771 I have tried the above mentioned code. Its working fine. But i need to export into excel 2007. I have tried so many ways.it does not working fine. If any one of them know how to do without error like"The file are you trying to open in a different xls format......."
rgds, Tharani
|
Title:
Excelente
Name:
Andres Lopez
Date:
2011-07-29 12:11:04 AM
Comment:
Viejo excelente funciono para web perfecto con formato y todo gracias por la ayuda
saludos thanks
|
Title:
Well, this is a bit unfinished?
Name:
ToB
Date:
2011-07-14 4:40:32 AM
Comment:
This will generate all the user controls within the output XLS... not great really
|
Title:
Many Thanks for the help
Name:
Angelo
Date:
2011-06-28 1:52:48 AM
Comment:
Thanks for the info mate. I was actually having an error: Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server. when exporting to excel..the override function fixed it :) thanks!
|
Title:
Export data to excel without error
Name:
B K
Date:
2011-06-21 8:12:36 AM
Comment:
I have tried this.It's working fine but there are errors.In thev excel sheet it is showing to put the gridview inside form tag whereas i have taken the gridview inside the form tag..Pls help.
|
Title:
Export to Excel the form data as well
Name:
Varun Sareen
Date:
2011-03-07 2:01:13 AM
Comment:
Dear Friends,
I need to export the form data also to the excel along with the grid data. How to do that??
|
Title:
how to save it directly
Name:
sapana
Date:
2011-02-28 1:16:10 AM
Comment:
hi.. excelent article as it helped me alot.. but the doubt tht arised while going through it was as how to save the exported excel sheet automatically to a folder without giving the option of open,save,cancel? thank u
|
Title:
Problem Solved
Name:
AT
Date:
2011-02-22 2:41:06 PM
Comment:
I am really grateful to you. I had been trying to add this functionality to my project for a long time. A lot of tries had been done before this and all had some problem or the other. This works like a charm... i once again thank u for this great piece of code......
|
Title:
Mr
Name:
Yogesh
Date:
2011-01-27 3:40:54 AM
Comment:
GridView1.RenderControl(htmlwriter) gives error
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
can't able to rid off that!!!!
|
Title:
error exporting in excel
Name:
Alma Mercado
Date:
2011-01-26 1:18:49 PM
Comment:
This article works for me. I'm using mater page with my forms. Thanks a lot
|
Title:
problem
Name:
rakesh
Date:
2010-11-30 1:21:30 AM
Comment:
i already done this code but its not working, it showing me Tooltip as download start but it unable to download
|
Title:
error at excel transfer
Name:
navaz
Date:
2010-11-18 8:47:09 AM
Comment:
private void button1_Click(object sender, EventArgs e) {
// creating Excel Application
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application(); // creating new WorkBook within Excel application
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing); // creating new Excelsheet in workbook
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
// see the excel sheet behind the program
app.Visible = true;
// get the reference of first sheet. By default its name is Sheet1.
// store its reference to worksheet
worksheet =(_Worksheet) workbook.Sheets["Sheet1"]; worksheet = (_Worksheet)workbook.ActiveSheet;
// changing the name of active sheet
worksheet.Name = "Exported from gridview";
// storing header part in Excel
for (int i = 1; i < dataGridView1.Columns.Count + 1; i++) {
worksheet.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;
}
// storing Each row and column value to excel sheet
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) {
for (int j = 0; j < dataGridView1.Columns.Count; j++) {
worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();
}
}
// storing Each row and column value to excel sheet
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) {
for (int j = 0; j < dataGridView1.Columns.Count; j++) {
workshe
|
Title:
Jayanth
Name:
Jayanth
Date:
2010-11-15 4:12:08 PM
Comment:
This code is the perfect code to do an export from a grid view.The dummy overiding event above matters a lot. Thanks, Jay
|
Title:
Nice
Name:
Terry
Date:
2010-10-07 1:42:09 PM
Comment:
@TJ if you get the:
I'm getting error: file you are trying to open, 'xxx.xls' is in a different format than speficied by the file extension. .......
Just open up the file and it should work fine.
|
Title:
this is really a good article
Name:
sankar
Date:
2010-09-27 3:36:35 AM
Comment:
Hi
I am not getting your Download Sample . It's showing 404 error would you give me your full code
|
Title:
Ok for Office 2003, but won't work for Office 2007
Name:
TJ
Date:
2010-09-09 12:46:07 PM
Comment:
Subject: Export GridView to Excel (xlsx, Excel 2007 Format) Your code will work for client with office 2003 or below, but not working for office 2007.
I'm getting error: file you are trying to open, 'xxx.xls' is in a different format than speficied by the file extension. .......
Does anyone have solution for client side office 2007?
|
Title:
Working Fine but...
Name:
Kalpen Patel
Date:
2010-09-06 2:46:36 AM
Comment:
Its working fine. Bt i want to know, what is the meaning of overriding this method as the method do not have code.
|
Title:
Nice articles
Name:
HallAurora
Date:
2010-08-16 2:42:15 AM
Comment:
Nice articles, did you used spire.xls ? I feel it other easy way to read and write excel. maybe best excel component to .net. too powerful !! http://www.e-iceblue.com/Introduce/excel-for-net-introduce.html
|
Title:
check the [Download Sample] link
Name:
RAM
Date:
2010-08-12 7:38:28 AM
Comment:
[Download Sample] is not working, please check it.
|
Title:
complaint
Name:
himanshu
Date:
2010-08-10 6:22:31 AM
Comment:
its not workn
|
Title:
very good one
Name:
Sekhar
Date:
2010-06-03 1:56:22 AM
Comment:
it works for me.. thanks for the post
|
Title:
Works Great!!!!
Name:
Anand
Date:
2010-05-07 1:41:26 AM
Comment:
I too had d similar error as "not placed in form tag" But now it works... Thanku...!!!
|
Title:
Try
Name:
Dude
Date:
2010-04-11 9:43:23 AM
Comment:
>RegisterForEventValidation can only be called during Render();
Try to disable, paging and sorting.
|
Title:
The problem I want a solution
Name:
abu ahmad
Date:
2010-03-16 5:04:27 AM
Comment:
When you export to spreadsheets show Arabic texts in the form of (???) I hope your help and thank you
|
Title:
Error Occurred
Name:
KarunagaraPandi
Date:
2010-03-04 6:53:43 AM
Comment:
I'm getting the following errrrrrrrrrrrrrrrr....
RegisterForEventValidation can only be called during Render();
|
Title:
Brilliant!
Name:
Megan
Date:
2010-02-27 4:36:55 PM
Comment:
Thank you so much. Literally copied and pasted with no adjustments and worked a treat!
|
Title:
Excellent
Name:
Mrunalini
Date:
2010-02-19 6:57:52 AM
Comment:
Hey,this article is gr8 n very usefull.I got the soluntion in few secs itself. Thanks a lot..........
|
Title:
Excellent
Name:
Siva
Date:
2010-02-17 2:07:09 AM
Comment:
Hey, this ariticle is fantastic. I get the code run in few minutes. Great! Earlier, I thought export the data to excel is bigger code, but this article gives me the result in no time. Awesome. Thanks much.
|
Title:
Coder
Name:
Arun
Date:
2010-01-28 3:01:14 PM
Comment:
Coool. Very useful article. Thanks a lot.
|
Title:
Not working
Name:
Carlos Arias
Date:
2010-01-14 12:15:51 AM
Comment:
If you are using ajax and master page put the button out of update panel protected void cmdExportar_Click(object sender, EventArgs e) { GridView2.AllowSorting = false; GridView2.AllowPaging = false; LigaDatos(); //Bind data StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page(); HtmlForm form = new HtmlForm(); GridView2.EnableViewState = false; page.EnableEventValidation = false; Page que requieran los diseñadores RAD. page.DesignerInitialize(); page.Controls.Add(form); form.Controls.Add(GridView2); page.RenderControl(htw); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=data.xls"); Response.Charset = "UTF-8"; Response.ContentEncoding = Encoding.Default; Response.Write(sb.ToString()); Response.End(); } ****ALSO public override void VerifyRenderingInServerForm(Control control) { /* Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. */
} *** AND EnabledEventValidation="false" <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" EnableEventValidation="false" Title="Buscar información" Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" %>
|
Title:
Hello
Name:
Sandeep choudhary
Date:
2010-01-07 10:51:46 AM
Comment:
Hello sir im facing some error in this code. error is u must declare gridview in form tag and check run at server or not....what i do
|
Title:
HELP!!!!
Name:
Alberto Nigra
Date:
2010-01-04 6:32:48 AM
Comment:
Hi, it gives me an error saying that another ImageButton (placed in the header of the page, so without any connection with my Export Button) must be placed in a form with the attribute "runat=server". But this ImageButton has nothing to do with my btn_Export. Any idea? Thanks for your time, Alberto
|
Title:
Code Download
Name:
Vijay parmar
Date:
2009-12-14 11:58:39 PM
Comment:
Hi
tha article is fine but public override void VerifyRenderingInServerForm(Control control) { /* Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. */}
i am not abal to understand and when i add page enable true and sortin true it shows error the link downloads not working
|
Title:
VB method
Name:
John Timms
Date:
2009-12-07 5:43:20 PM
Comment:
Hi,
Great article! There is a similar method in VB described at 503 "service unavailable" errors when IIS running in 32-bit mode on 64-bit Windows Server 2008
|
Title:
Export to excel
Name:
Ali shariff
Date:
2009-11-11 6:01:10 AM
Comment:
Thanks... realy looking for this kind of code
|
Title:
Export gridview to excel
Name:
Tom
Date:
2009-11-06 8:42:00 AM
Comment:
I have a gridview that is in a panel, and still get the registerforeventvalidation... message at the
GridView1.RenderControl(htmlWrite); line
Any suggestions.
If the grid is not in a panel, the code works well.
|
Title:
User control and paging
Name:
SAM
Date:
2009-10-04 4:15:08 AM
Comment:
This is how to get all the data when your GridView has paging. Goes in Page_Load if in a ascx, otherwise you can put this in the onclick event.
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { GridView1.AllowSorting = false; GridView1.AllowPaging = false; GridView1.DataBind(); };
}
Also noticed that lots of people forget your step three in the article...add this to the aspx page AND set EnableEventValidation="False"
Listing 3: Overiding VerifyRenderingInServerForm Method
public override void VerifyRenderingInServerForm(Control control) { /* Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. */}
|
Title:
Export to excel
Name:
Vicky Lin
Date:
2009-09-13 3:35:53 PM
Comment:
I have still error in Response.End(). I want to jump another page after clicking open or save in the excel file download dialog box.Is it possible?
|
Title:
Export to Exel
Name:
Ashish MIshra
Date:
2009-09-12 6:13:06 AM
Comment:
Code Works No doubt but the problem is that when we run application then first time file open in Exel format but at that time without closing the application we open in Exel Formet then file not open.
|
Title:
GridView with paging
Name:
Sivakumar
Date:
2009-09-11 1:13:20 PM
Comment:
The above code is not working it throws error when the grid has more than a page. Is there any solution for this?.
|
Title:
hi
Name:
dharmveer
Date:
2009-08-26 11:57:53 AM
Comment:
THANKS, IT'S WORKING EASILY BUT I HAVE A PROBLEM IN SQL SERVER CONNECTION THAT IS SILVED USING DATAADAPTOR.........
|
Title:
Overiding VerifyRenderingInServerForm Method
Name:
Stephen Moseley
Date:
2009-08-14 5:03:52 PM
Comment:
This was very helpfull! Solved my problem. I hope your link makes it higher up on google. There were lots of others above this article which missed the Overiding VerifyRenderingInServerForm Method.
Thanks!!!
|
Title:
How to save this excel file in my given format 002
Name:
Ganesh
Date:
2009-08-04 5:33:57 AM
Comment:
Hi, My Datatable contains value 002 whenever i download in Datatable to Excel. It shows only 2 but i need the following format 002 in Excel download file(Using ASP.Net-05, C#).Is it possible. Thanks
|
Title:
Overiding VerifyRenderingInServerForm Method
Name:
MOHAMMAD JAVED
Date:
2009-07-28 4:53:14 AM
Comment:
Eexcellent code.
|
Title:
it really works perfectly fine
Name:
gaurav
Date:
2009-07-24 2:24:46 AM
Comment:
u r really fantastic... i was struck in this for so long n i jst copied ur code and pasted it and it worked in one go.. thnx a tonn..
|
Title:
Kirandeep singh
Name:
Singh
Date:
2009-07-20 2:40:11 AM
Comment:
Hi,
this code is giving me the parsing error, i have tried to search solution for that but it is saying to remove response.write from code because that is the beast causing the problem.
Is there any work around for this.
Please reply thanks in advance
|
Title:
Thankd
Name:
Enis Karahanlı
Date:
2009-06-25 7:09:21 AM
Comment:
Thank you I need that really
|
Title:
G8
Name:
JC
Date:
2009-06-15 2:29:11 AM
Comment:
I was wondering by seeing this error msg. just I copied ur code it is working fine. Really ur Great...
|
Title:
Thanks
Name:
Shantanu
Date:
2009-06-08 11:34:02 PM
Comment:
Boss ur r great
|
Title:
Export to excel
Name:
Vivek Jain
Date:
2009-06-08 2:37:03 AM
Comment:
Can any one help me for solve his Problem without using EnableEventValidation="False" Error:"RegisterForEventValidation can only be called during Render()" Due to Security Region i don't want to off enableEventValidation.Thanks for any help.
|
Title:
Still having Problem with Grid Display
Name:
Namrata Chokhani
Date:
2009-06-03 7:43:19 AM
Comment:
Thanks for making this wonderful code available. But I'm still having a problem with this code as my Grid View is placed inside a Content Page. It needed a form tag. Hence I changed the code to
HtmlForm frm = new HtmlForm(); Response.Clear(); Response.AddHeader("Content-Disposition", "Attachment; FileName = Report.xls"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "Application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
frm.Controls.Add(grdView); this.Controls.Add(frm); frm.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString()); Response.End();
This give me an exception as 'Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.'
If I comment 'Response.End()' a message of 'Use only one Form Tag on a Page' is given
|
Title:
Deformed gridview
Name:
Ichiro
Date:
2009-05-10 11:21:14 PM
Comment:
Thanks for the solution! But there's a little problem, though. If my gridview has some cells that span rows, the output gridview on the XLS file is deformed. Could this be due to the removed cells to give way to the spannings? If so, is there a way for it to export the gridview "as is"? Thanks for any help.
|
Title:
Developer
Name:
Pradeep
Date:
2009-05-02 1:06:23 AM
Comment:
Thanks for the Post. It worked form me.
|
Title:
problem fixed
Name:
James
Date:
2009-04-08 8:23:06 PM
Comment:
man u solved the form runat=server issue with that override. everywhere else online faffed around. nice one. cheers. now i can go to bed :) thanks.
|
Title:
Thank you for giving this export from gridview to excelsheet
Name:
shravan
Date:
2009-03-09 6:46:00 AM
Comment:
Hello sir, iam shravan. Thank you very much to given code. This is very useful sir. i Just copy the code and paste in my webpage its working with out errors Thank you!
|
Title:
Developer
Name:
prasanna
Date:
2009-02-25 5:39:50 AM
Comment:
I used your code but i got follow Error message . can any one help me? Error says: RegisterForEventValidation can only be called during Render()
|
Title:
Memory exceeded
Name:
arif budiman
Date:
2009-02-25 2:49:55 AM
Comment:
Memory exceeded if you export more than 60000 rows, any one have another way, thanks for snippet code
|
Title:
thanks but it not work in Arabic language
Name:
Anas
Date:
2009-02-17 9:21:43 AM
Comment:
thanks but it not work in Arabic language
|
Title:
for windows application
Name:
Pankaja
Date:
2009-02-05 1:51:41 AM
Comment:
I have done similar coding as per your code, but the data displayed in a GridView Control is not being displayed in an Excel Sheet in which i am trying to save the data. The Excel sheet is being displayed blank.
Please help me out.
pankaja6dingare@yahoo.com
|
Title:
sumanta
Name:
das
Date:
2009-01-09 6:44:22 AM
Comment:
Its working. Thanks a lot
|
Title:
Export many gridview
Name:
Stéphane
Date:
2008-12-29 5:43:17 AM
Comment:
Hi I would like to export several gridviews using this method in only one excel files, which contains as many sheets than gridview. Could you please help me. Thank you for all
|
Title:
Export to Excel
Name:
Bhanu
Date:
2008-12-26 2:10:43 AM
Comment:
I Worked with above code.It worked exactly as said above.Thanks for the code.
|
Title:
How to save this excel file in my given location.
Name:
Umesh
Date:
2008-12-18 6:06:47 AM
Comment:
I used above code to export the file from Gridview to excel.But it automatically save the excel file at Temp folder. I want to save excel at my given location. How can i do this ?
umesh.chape@aurovision.com
|
Title:
Eport to Excell
Name:
Taqi
Date:
2008-12-15 11:56:45 PM
Comment:
How to export GridView(Which consists of more than one pages)to Excel File.
Take Care.
|
Title:
Eport to Excell
Name:
Asmi
Date:
2008-12-12 4:29:14 AM
Comment:
i used the same code but i got following error Error says: RegisterForEventValidation can only be called during Render()
|
Title:
Export to excel
Name:
Anoop Ravi
Date:
2008-12-08 4:56:34 AM
Comment:
worked well.. thank you.
|
Title:
Developer
Name:
Amir
Date:
2008-12-02 3:49:57 AM
Comment:
I used your code but i got follow Error message . can any one help me? Error says: RegisterForEventValidation can only be called during Render()
|
Title:
Export to excel
Name:
Navya
Date:
2008-11-28 12:15:58 AM
Comment:
Good article,but how to export data in two gridview controls to different tabs(sheets) in single excel workbook(file).
|
Title:
Overiding VerifyRenderingInServerForm Method : WorkAround for User Control
Name:
Mano Mangaldas
Date:
2008-11-20 11:24:37 PM
Comment:
ref : http://aspnet.4guysfromrolla.com/articles/102203-1.2.aspx
int GridControlPosition = this.Controls.IndexOf(GViewResults);
Page p = new Page(); HtmlForm hf = new HtmlForm();
p.Controls.Add(hf); hf.Controls.Add(GViewResults);
StringBuilder SB = new StringBuilder(); StringWriter SW = new StringWriter(SB); HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
p.DesignerInitialize(); p.RenderControl(htmlTW);
p = null;
String dataGridHTML = SB.ToString();
String SearchContent = Server.HtmlEncode(dataGridHTML);
this.Controls.AddAt(GridControlPosition, GViewResults);
|
Title:
alternate for User Control
Name:
Mano
Date:
2008-11-20 11:22:43 PM
Comment:
int GridControlPosition = this.Controls.IndexOf(GViewResults);
Page p = new Page(); HtmlForm hf = new HtmlForm();
p.Controls.Add(hf); hf.Controls.Add(GViewResults);
StringBuilder SB = new StringBuilder(); StringWriter SW = new StringWriter(SB); HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
p.DesignerInitialize(); p.RenderControl(htmlTW);
p = null;
String dataGridHTML = SB.ToString();
String SearchContent = Server.HtmlEncode(dataGridHTML);
this.Controls.AddAt(GridControlPosition, GViewResults);
|
Title:
Developer
Name:
Sree
Date:
2008-11-05 5:41:13 AM
Comment:
Though i have used the same code i am still getting error that "RegisterForEventValidation" can only be called in Render()....
Thanks, Sree
|
Title:
Developer
Name:
Jim
Date:
2008-09-08 2:33:50 PM
Comment:
Thank you ... BTW: this works for all different types of code situations...
(I suspect you knew that however this helpful tid-bit might help other people who don't know it works in other situations....)
Jim
|
Title:
For Windows Application
Name:
Agnes Loyola
Date:
2008-08-06 11:53:29 PM
Comment:
can anyone give the code to export gridview to Excel sheet in windows application.
|
Title:
For Windows Application
Name:
Agnes Loyola
Date:
2008-08-05 11:37:30 PM
Comment:
Can anyone help me to do the same for Windows application? Please ....... its very urgent
|
Title:
nice article
Name:
vinod
Date:
2008-07-10 2:16:50 AM
Comment:
hi this is nice article for creating or genrating report in execel file ....
|
Title:
Opening a new window
Name:
Andres
Date:
2008-04-16 7:12:56 PM
Comment:
Hi, i'm having an issue when doing the exportation in a new window. What i'm doing is to store the grid in session, then i open a new window, in the Page_Load i have the same code you have in the btnExport_Click, everything works fine if i run the app in localhost, but, if i access it from a client window and run the exportation, it opens the window and before something gets render it disappears. This only happens when i access the app from another client browser (i mean without using localhost). And if i disable all the code inside the new page it opens without any problem. Any suggestions or solutions would be appreciated.
|
Title:
Exporting GridView to Excel
Name:
Praew
Date:
2008-04-11 3:17:04 AM
Comment:
That's cool Thank you for your code.
|
Title:
Few Records to Export
Name:
Dilip
Date:
2008-04-10 2:21:21 AM
Comment:
Your code is working fine but i want to export only few records from a gridview with header repeating in excel sheet. any suggestion?
|
Title:
You Rule!
Name:
JR Miller
Date:
2008-03-18 4:29:24 PM
Comment:
First time through and the example worked without a hitch! Excellent, learned and created, what more could one want.
Thanks!
|
Title:
thanks
Name:
I. Sam Asir Aloysious
Date:
2008-03-11 1:36:16 AM
Comment:
Really helpfull
|
Title:
Thanks
Name:
Kiran
Date:
2008-03-08 3:52:41 AM
Comment:
Keep it up !!!!!!
|
Title:
Thank You
Name:
Mahesh
Date:
2008-02-25 2:45:35 AM
Comment:
Hi, Thank you for giving this code. It helps me a lot.
|
Title:
export to pdf
Name:
cs
Date:
2007-12-20 11:10:07 AM
Comment:
Is there a possibility that we can export the gridview to pdf? Thanks, CS
|
Title:
GridView to Excel Export
Name:
Shanmugam K
Date:
2007-12-12 5:15:37 AM
Comment:
Its doesn't work when my page as Child Page - (I used Master Screen for my project)
any help? thanks in advance
|
Title:
Real Excel 2003 or Excel 2007 export
Name:
Ettore
Date:
2007-12-11 4:48:31 PM
Comment:
This is the "usual" HTML export. It works only when you have a few records to export to Excel. If you have a lot to export simply doesn't work. Then You have to use real XML export to Excel 2003 or xlsx export to Excel2007.
Try http://www.gridviewtoexcel.com
|
Title:
Great!
Name:
Alv
Date:
2007-12-10 2:09:26 AM
Comment:
Hey!!! Thanks man! It's working perfectly for me!
|
Title:
Good Example
Name:
Mohammed Irfan
Date:
2007-12-06 4:56:18 AM
Comment:
It works perfecltly, after setting EnableEventValidation="False" in <%@ %> tag, to overcome the error: "RegisterForEventValidation can only be called during Render();"
Thank you
|
Title:
Export to Excel
Name:
Sandeep kumar
Date:
2007-12-05 10:52:44 PM
Comment:
Thanks it's working.
|
Title:
Export to Excel
Name:
ettore
Date:
2007-12-05 6:59:08 AM
Comment:
Please try http://www.gridviewtoexcel.com
|
Title:
Thanks... Can u answer my question ?
Name:
Yuvaraj
Date:
2007-11-14 7:09:13 AM
Comment:
U gave a good information to us... but can u explain what is the use of the method VerifyRenderingInServerForm(Control control) , with out this why the application show the error... can explain this mechanism please....
|
Title:
Thank You
Name:
Reena Dahiya
Date:
2007-11-05 2:12:18 AM
Comment:
Thanks for writing the article that help me lot.Thank you very very much.
|
Title:
Thanks!
Name:
Pranalee Shirodkar
Date:
2007-10-13 2:08:27 AM
Comment:
Thanks for writing this article..
|
Title:
opening download dialog box
Name:
Tushar
Date:
2007-10-03 6:23:40 AM
Comment:
Problem: presently m writing it onto .aspx page on which i have the GridView. The problem is it is opening the download dialog box as soon as code reaches Response.End(); and not in the path i give with filename.
Requirement:= Please anyone give me the code that i can put into a .cs file and by passing the GridView to its method i can call in any aspx page.
VerifyRenderingInServerForm doesn't work when i put it inside a cs file..
|
Title:
Exports whole page instead of GridView1
Name:
Josh
Date:
2007-10-01 4:12:10 PM
Comment:
Hello- I am getting the entire aspx page exported into my xls file intsead of just the GridView1. I do have a Response.End(); in my BtnExport_Click procedure. Any ideas?
|
Title:
I like that
Name:
Sarp Arad Coskun
Date:
2007-09-25 3:10:04 PM
Comment:
Overiding VerifyRenderingInServerForm Method idea helped me a lot, thanks.
|
Title:
Error
Name:
Basir
Date:
2007-09-18 12:10:42 PM
Comment:
Hello, I get the following error:
RegisterForEventValidation can only be called during Render();
This happens on my line GridView1.RenderControl(htmlWrite) in vb.net. Please help!
Basir
|
Title:
VB Code
Name:
Sun
Date:
2007-09-04 3:39:47 PM
Comment:
Dim stringWrite As IO.StringWriter Dim htmlWrite As HtmlTextWriter Dim frm As HtmlForm = New HtmlForm()
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-xls"
stringWrite = New IO.StringWriter
htmlWrite = New HtmlTextWriter(stringWrite)
Controls.Add(frm) frm.Controls.Add(WeldGridView) frm.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
|
Title:
Missing a Using
Name:
Marco van Maanen
Date:
2007-08-31 7:16:57 AM
Comment:
Hello I have try'd your code but I get so far oné error.. Is there enywone hire who can help mee solf te problem? Error: CS0246: The type of namespace name 'SqlConnection' could not be fount (are you missing a using directive or an assembly reference ? )
It is in my file on line: 25
Thanx.
|
Title:
FIX for export downloading whole ASP page
Name:
Daniel Weltman
Date:
2007-08-24 2:15:24 PM
Comment:
Hi I just realized the fix for when the excel export downloads the whole ASPX page.
You have to make sure to end the response:
HttpContext.Current.Response.End();
Thanks
Daniel
|
Title:
Just what I was looking for
Name:
Bilal Patel
Date:
2007-08-13 9:51:57 AM
Comment:
Thanks for this. It's just what I was looking for. I'm a newcomer to .NET and this was worrying the hell out of me. Thanks for explaining how to do the override.
|
Title:
Problems with MasterPages
Name:
TroubledMan
Date:
2007-08-06 12:25:03 PM
Comment:
I tooo recieve an error where using a gridview in a contentpage... Even if i've a masterpage with a runat=server form, when I try to export i get an error: ctl00_ContentPlaceHolder1_grvMyGrid' of type GridView must be placed inside form tag with runat = server...
HELP ME PLEASE! ;)
|
Title:
save xls file directly on server's hard drive
Name:
Alberto Moura
Date:
2007-08-01 12:56:00 PM
Comment:
how I can save the xls file directly on server's hard drive to send after by email?
tanks in advance! Alberto Moura
|
Title:
Thanks tons!!!
Name:
Donald James Parker
Date:
2007-07-27 12:49:30 PM
Comment:
This was a wonderful thread. Saved me a bunch of time. My grid would not render - due to the fact it is contain with an asp:content block, I believe. The creation of a new webform with the grid on it did the trick. Thanks so much!!!
|
Title:
Exporting to excel..
Name:
sam
Date:
2007-07-16 6:05:29 AM
Comment:
Hi, i'm exporting grid view in excel its saving it properly, but when i try to open it without saving, it is giving error, actually i'm not using the parameter "Object Sender" insted i'm using HttpResponse since i'm using class library for the function..actully first it saves the file in temporary files..i've used the code Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); but still it saves it first in temporay internent file, it works fine first time but second time it searches the file with [1] in temp int. files folder and doesnt gets it..pls help me..
|
Title:
Turn Paging and Sorting Off On Export
Name:
David Wilkes
Date:
2007-07-12 2:10:22 PM
Comment:
Code is good. I added the following three lines at the top of the button click event. Allows all the content to be exported and removes the hyperlinks.
GridView1.AllowSorting = false; GridView1.AllowPaging = false; GridView1.DataBind();
|
Title:
Another Solution for RegisterForEventValidation
Name:
Scottie
Date:
2007-07-11 4:16:42 AM
Comment:
Another technique to prevent the RegisterForEventValidation problem is to make columns/controls that accept input not visible, e.g. Control.Visible = false. In my case, I had a column that contained checkboxes; when I set the visibility of that column off, I avoided the error.
|
Title:
It Works..
Name:
Awadhesh Kumar Singh
Date:
2007-07-05 5:53:30 AM
Comment:
Hello Friends Code under title 'Exporting GridView to Excel' works..No Problem at all. I have just tried it.
|
Title:
Works good.
Name:
Mistry
Date:
2007-07-03 1:29:59 PM
Comment:
It works good with 2 additions:
1) EnableEventValidation="False" in <%@ %> tag in aspx file.
2) as suggested in listing 3 above.
Thanks for providing this and now how to take out the hyperlinks in the fitst row?
Thanks!
|
Title:
i need solution for Error also with Runat=Server
Name:
wael from egypt
Date:
2007-06-18 9:27:23 AM
Comment:
write this code
HtmlForm frm = new HtmlForm();
GridView1.Controls.Add(frm); frm.Attributes["runat"] = "server"; frm.Controls.Add(grdvwResults); frm.RenderControl(htmlWrite);
and comment the line
//GridView1.RenderControl(htmlWrite);
thanks
wael from egypt
|
Title:
Thanks
Name:
Tijo Joseph
Date:
2007-05-30 5:57:27 AM
Comment:
Thanks for the article!Iam facing a problem that this code export whole aspx page to the Excel sheet instead of exporting only the Grid view content.
|
Title:
Excellent
Name:
John S
Date:
2007-05-15 11:17:04 AM
Comment:
Thanks for this article, got me going in minutes, Excellent !
|
Title:
thanks a bunch!
Name:
Muhammed Ibrahim
Date:
2007-05-14 1:32:00 AM
Comment:
This article was precise and very well defined. Helped me a lot. (for the comment below to A.R.R) please read the article completely ARR. the author has mentioned a fix for the error message to your problem.
|
Title:
MasterPage
Name:
A.R.R.
Date:
2007-05-11 12:05:54 PM
Comment:
Ok, and what about if the site is within a masterpage. I got an error! Control 'ctl00_ContentPlaceHolder1_gridAttendees' of type 'GridView' must be placed inside a form tag with runat=server
|
Title:
CodeSnip: Exporting GridView to Excel
Name:
Ashish Singh
Date:
2007-05-10 2:46:49 AM
Comment:
Superb !
Good One !
|
Title:
RegisterForEventValidation can only be called during Render()
Name:
Matt Berseth
Date:
2007-04-25 8:49:39 PM
Comment:
I didn't want to override VerifyRenderingInServerForm, had problems with the "Control GridView1" must be placed inside the form tag with runat=server" exception and wanted to move this logic out of the pages and into a utility class. Here is the solution I came up with - it has been working great: http://mattberseth.com/blog/2007/04/export_gridview_to_excel_1.html
|
Title:
Error Fixed
Name:
ThomasP
Date:
2007-04-18 12:33:36 PM
Comment:
Nevermind on the Runat Server error I had to add the function
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
& Set the EnableEventValidation="False" in the HTMl
|
Title:
Error also with Runat=Server
Name:
ThomasP
Date:
2007-04-18 11:49:24 AM
Comment:
I am also reciving the error ***Control 'ctl00_ContentPlaceHolder1_gridAttendees' of type 'GridView' must be placed inside a form tag with runat=server.**** Anyone have any ideas?
|
Title:
Error on Export to Excel
Name:
senthil
Date:
2007-04-18 9:03:26 AM
Comment:
http exception occuring while using the above code: "Control GridView1" must be placed inside the form tag with runat=server" pointing to "GridView1.RenderControl(htmlWrite);" line of your code
But,the gridview control is already in the form tag with runat=server
|
Title:
Export to excel_facing error
Name:
Ajay
Date:
2007-04-14 2:19:55 PM
Comment:
http exception occuring while using the above code: "Control GridView1" must be placed inside the form tag with runat=server" pointing to "GridView1.RenderControl(htmlWrite);" line of your code
But,the gridview control is already in the form tag with runat=server
|
Title:
RegisterForEventValidation can only be called during Render()
Name:
user
Date:
2007-03-31 12:31:35 PM
Comment:
i use the code above 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 called during render)how will i resolved these problem without setting the EnableEventValidation to false.
|
Title:
Thankyou for writing this article
Name:
Stephan Ryer
Date:
2007-03-29 4:06:44 AM
Comment:
Thankyou for writing this article. It solved a problem I have been trying to solve for hours.
Thanks again :)
/Stephan Ryer
|
Title:
To: Michael Re:Pageable Sortable Gridview not exporting correctly
Name:
Stefan
Date:
2007-03-22 7:50:41 AM
Comment:
Hi, I am experiencing the same problem. It looks like it's an Office 2007 issue... (they claimed it would be fixed... but doesn't look like :-()
|
Title:
Troubled by RegisterForEventValidation exception
Name:
Cherrie
Date:
2007-03-01 4:34:59 PM
Comment:
One can set EnableEventValidation in the page directive. Can you set it in the code-behind? I tried but it is not exposed. Thanks.
|
Title:
Here is somethig Too good
Name:
Nacho
Date:
2007-02-03 2:20:54 AM
Comment:
I found this solution for this problem RegisterForEventValidation can only be called during Render.
I have to insert this text at the begin of the page (souce view) <%@ Page EnableEventValidation="False" Language="VB"...%> and my button to export Works Ok.
I hope this can Help You.
|
Title:
Pageable Sortable Gridview not exporting correctly
Name:
Michael Lashinsky
Date:
2007-01-27 8:30:31 PM
Comment:
I have turned followed the example above (pertaining to VB.NET). When I open the file generated by this codebehind for the click event:
Protected Sub lnkbtnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkbtnExport.Click If grdCustomerData().Rows.Count + 1 < 65536 Then grdCustomerData().AllowPaging = False grdCustomerData().AllowSorting = False grdCustomerData().DataBind() Dim tw As New StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) Dim frm As HtmlForm = New HtmlForm() Dim FileName As String = "BillingWorkSheet" & Date.Now.ToShortDateString Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "attachment;filename =" & FileName & " report.xls") Response.Charset = "" EnableViewState = False Controls.Add(frm) frm.Controls.Add(grdCustomerData()) frm.RenderControl(hw) Response.Write(tw.ToString()) Response.End() grdCustomerData().AllowPaging = True grdCustomerData().AllowSorting = True grdCustomerData().DataBind() Else LblError.Text = "Too many rows - Export to Excel not possible"
End If End Sub
I recieve the error the file you are trying to open, [FileName], is in a different format than specified by the file extension. Verify that the file is not corrupted, and is from a trusted source before opening the file. Do you want to open the file now? [Yes] [No] [Help]
I was under the impression that this was caused by the client side javascript used to sort and page the columns and that if I set the value of the sortable, pageable properties to false before generating the excel document that this would correct this problem. Has any one had success with exporting a pageable sortable GridView
|
Title:
Exporting a part of page to XLS file
Name:
Imran
Date:
2007-01-16 8:12:32 AM
Comment:
I need to export a part of page to XLS file, that is, I want to export the data in an HTML table to XLS file. I am using a DataReader to retrieve data from the db and display it on the webpart.
|
Title:
Still won't work for me
Name:
Matt
Date:
2006-12-24 1:46:29 PM
Comment:
I tried using this code to export my gridview into excel and I keep getting the RegisterForEventValidation can only be called during Render(); error. I have added all the pieces shown on this page, plus turned off sorting/paging, but still get the render error. I don't want to turn off event validation, is there anything else I can try.
|
Title:
Re: Exporting GridView to Excel
Name:
AzamSharp
Date:
2006-11-22 7:34:24 PM
Comment:
Hi,
You can also export the DataSet or your container to the Excel. Check out the article at the following link.
http://gridviewguy.com/ArticleDetails.aspx?articleID=215
|
Title:
EnableEventValidation
Name:
Mariana
Date:
2006-11-22 2:54:58 PM
Comment:
Turning off event validation is not a very good idea. Do it at your own risk, and only if you're sure there's no postback that can compromise your site.
I was able to get around it by disallowing sorting and paging as explained in some of the comments above. In fact, this works much better because now all of the data gets downloaded to Excel. The user can use Excel to sort the downloaded data.
I translated Hoa Ngyen's code to C# (thanks!!). I used local variables to save the original grid settings, and reset them after the export.
|
Title:
EnableEventValidation
Name:
Gary
Date:
2006-11-10 10:24:04 AM
Comment:
Thank you for the article and to those who provided a fix for the "RegisterForEventValidation can only be called during Render();" error I was also stumped until I set EnableEventValidation="false".
|
Title:
Miss
Name:
Chirtwin
Date:
2006-11-09 9:07:19 AM
Comment:
life saver on the 'Overiding VerifyRenderingInServerForm Method'
|
Title:
Exporting more than the current page of the grid view.
Name:
Stephen Biggs
Date:
2006-10-10 10:20:55 AM
Comment:
The Gridview usually only displays about 10 lines. You can cause the excel file to contain more (or all) of the dataset. By changeing the code to increase the gridview. Pagesize & rebind the data. Then switch back to the standard pagesize after the export is complete e.g; Me.GridViewSearch.PageSize = ds.count Me.GridViewSearch.DataSource = ds Me.GridViewSearch.DataBind() Me.GridViewSearch.RenderControl(htmlWrite) Response.Write(stringWrite.ToString()) Response.End() Me.GridViewSearch.PageSize = 10 Me.GridViewSearch.DataSource = ds Me.GridViewSearch.DataBind()
|
Title:
Thanks
Name:
Ozay
Date:
2006-09-21 4:59:16 PM
Comment:
Thank you very much for this article.. I find everywhere, Thanks God I find this by you. ;)
|
Title:
Exporting GridView with Links
Name:
Azamsharp
Date:
2006-08-08 6:19:25 PM
Comment:
Hi Yogi,
I see. I have found the fix for this problem. What you can do is to convert all the links inside the GridView into literal controls this way they will be exported as text. I made an entry in my blog. Wow! after much search I finally found that blog entry here it is:
http://geekswithblogs.net/azamsharp/archive/2005/08/21/50774.aspx
I am sure that this link will help you.
|
Title:
So what is the problem?
Name:
AzamSharp
Date:
2006-08-08 6:02:44 PM
Comment:
Hi,
What is the problem that you are facing?
Thanks, Azam
|
Title:
there is problem
Name:
yogi
Date:
2006-06-16 1:08:02 PM
Comment:
i am using this method to export to excel. it works fine if you have a simple gridview. but if you have select or edit columns in gridview it throws render error. i put a try catch in the button code and i was able to export it but it exports the whole html page instead of just the gridview . can any body help in solving this problem
|
Title:
Thanks!
Name:
NewToASPNET
Date:
2006-06-14 7:08:43 PM
Comment:
Thanks a lot for the code, it works!
Questions: 1. Where is the xls file after it is generated? Is it on the server? Do you have to clean it up later from the server? Do you have to use a unique file name? would it be a problem if multiple users are exporting at same time?
2. If I am not using GridView, but using a HTML table, is it possible to download it into a xls file?
Thanks a lot!
|
Title:
Re: Exporting Issues
Name:
AzamSharp
Date:
2006-05-29 11:32:27 AM
Comment:
Hi,
Try making the controls inside the GridView invisible and then try exporting the GridView. Once, the GridView is exported successfully you can make the controls visible again.
Hope it helps! Azam
|
Title:
similar exception for RegisterForEventValidation method
Name:
Bibhakar Saran
Date:
2006-05-29 1:49:16 AM
Comment:
Where GridView has child control in columns (eg. Checkbox, DropDownList, etc) throws similar exception for RegisterForEventValidation method, even after overriding the VerifyRenderingInServerForm method.
What could be an appropriate resolution for this issue.
|
Title:
Sweet
Name:
CK
Date:
2006-05-26 9:10:50 AM
Comment:
Thanks so much for posting this solution. I used one of the many C# to VB.NET converters available and this worked perfectly in my VB environment.
|
Title:
export to excel
Name:
hoa nguyen
Date:
2006-04-20 12:18:32 PM
Comment:
here is how to allow sorting at the time when exporting to excel. this code is from code behind
Sub doExcel(ByVal Source As Object, ByVal E As EventArgs)
If remain_capacity_grid.Rows.Count + 1 < 65536 Then remain_capacity_grid.AllowPaging = False remain_capacity_grid.AllowSorting = False remain_capacity_grid.DataBind() Dim tw As New StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) Dim frm As HtmlForm = New HtmlForm() Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "attachment;filename= report.xls") Response.Charset = "" EnableViewState = False Controls.Add(frm) frm.Controls.Add(remain_capacity_grid) frm.RenderControl(hw) Response.Write(tw.ToString()) Response.End() remain_capacity_grid.AllowPaging = True remain_capacity_grid.AllowSorting = True remain_capacity_grid.DataBind() Else LblError.Text = "Too many rows - Export to Excel not possible"
End If End Sub
|
Title:
Removing rendering error in VB
Name:
Liam
Date:
2006-04-12 7:15:14 AM
Comment:
Taking off allow sorting resolves this, not sure how to allow sorting at same time.
|
Title:
UserControl
Name:
Kareem
Date:
2006-04-07 10:39:19 AM
Comment:
How can this be done from a usercontrol? This works great in page. I've moved all this into a usercontrol but I can't override VerifyRenderingInServerForm from a usercontrol. Any thoughts?
|
Title:
Error rendering
Name:
steve
Date:
2006-04-02 11:15:50 AM
Comment:
Hi, thanks for the tutorial.
However i get this error when the page postsback when i click export button. RegisterForEventValidation can only be called during Render();
Any ideas? thanks steve
|
Title:
vb code
Name:
carcher
Date:
2006-03-31 12:31:12 PM
Comment:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control)
' Do NOT call MyBase.VerifyRenderingInServerForm
End Sub
|
Title:
Code in VB?
Name:
JPG
Date:
2006-03-17 12:58:43 PM
Comment:
Do you have the equivalent in VB? The VerifyRenderingInServerForm doesn't seem to work in VB.
Thanks,
JPG
|
Title:
Continue with error(2)
Name:
dperez
Date:
2006-03-12 2:05:17 PM
Comment:
my email is dperez1578@gmail.com.
thkx again,
dperez
|
Title:
Continue with Error
Name:
dperez
Date:
2006-03-12 1:53:55 PM
Comment:
Hey, nice info.
I did everything that u mentioned but i an still havin problems with the export(gridview to excel).
I was getting the error of the gridview neddeing to be in a form tag + a run at server, with the override igor rid of it but know i have the problem withc says
"RegisterForEventValidation can only be called during Render();"
what can i do
i appriciate any help
drp
|
Title:
Thanks!
Name:
N8NDREW
Date:
2006-03-06 2:32:05 PM
Comment:
Mr. Azam, thanks for the advice, works great. I encountered the problem with rendering that some of the others have indicated, but since mine was a read only page. It was not an issue to turn off validation. This is a very common requirement we should try and come up with a better solution it.
|
Title:
Even Though Nothing New, It Helped
Name:
David Anderson
Date:
2006-02-20 1:22:26 PM
Comment:
Thanks for the comments at the end about overiding VerifyRenderingInServerForm. That got me out of a bind.
|