473,386 Members | 1,823 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,386 software developers and data experts.

Export datagrid(with allowsorting) to Excel

Dear All,

I want to export datagrid content to a Excel file, the code just like below:

Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
gridList.Columns(0).Visible = False
gridList.Columns(1).SortExpression = ""
gridList.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

....

If my datagrid Allowsorting=true, then the code run error,but if I config the Allowsorting=false, then above code run fine.
Please help me how to export if my datagrid has the allowsorting properity.

Any help welcomes.

Best Regards,
Eric.
Nov 17 '05 #1
6 5863
In this instance, since you know what the user wants when you query the
data, I would consider sorting the data on the server when you pull the
data. I am not sure why it bombs (I would have to examine the HTML
produced), but it is easily solved by sorting on the Data tier and avoiding
the issue on the Presentation tier.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

************************************************** **************************
****
Think Outside the Box!
************************************************** **************************
****
"Eric" <Er******@hotmail.com> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
Dear All,

I want to export datagrid content to a Excel file, the code just like
below:

Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
gridList.Columns(0).Visible = False
gridList.Columns(1).SortExpression = ""
gridList.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

....

If my datagrid Allowsorting=true, then the code run error,but if I
config the Allowsorting=false, then above code run fine.
Please help me how to export if my datagrid has the allowsorting
properity.

Any help welcomes.

Best Regards,
Eric.
Nov 17 '05 #2
what he said, sort on the data layer

"Cowboy (Gregory A. Beamer)" <No************@comcast.netRemuvThis> wrote in
message news:Od*************@TK2MSFTNGP11.phx.gbl...
In this instance, since you know what the user wants when you query the
data, I would consider sorting the data on the server when you pull the
data. I am not sure why it bombs (I would have to examine the HTML
produced), but it is easily solved by sorting on the Data tier and avoiding the issue on the Presentation tier.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

************************************************** ************************** ****
Think Outside the Box!
************************************************** ************************** ****
"Eric" <Er******@hotmail.com> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
Dear All,

I want to export datagrid content to a Excel file, the code just like
below:

Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
gridList.Columns(0).Visible = False
gridList.Columns(1).SortExpression = ""
gridList.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

...

If my datagrid Allowsorting=true, then the code run error,but if I
config the Allowsorting=false, then above code run fine.
Please help me how to export if my datagrid has the allowsorting
properity.

Any help welcomes.

Best Regards,
Eric.

Nov 17 '05 #3
Would you like to tell me how to do?
Thanks.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netRemuvThis> дÈëÏûÏ¢
ÐÂÎÅ:Od*************@TK2MSFTNGP11.phx.gbl...
In this instance, since you know what the user wants when you query the
data, I would consider sorting the data on the server when you pull the
data. I am not sure why it bombs (I would have to examine the HTML
produced), but it is easily solved by sorting on the Data tier and avoiding the issue on the Presentation tier.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

************************************************** ************************** ****
Think Outside the Box!
************************************************** ************************** ****
"Eric" <Er******@hotmail.com> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
Dear All,

I want to export datagrid content to a Excel file, the code just like
below:

Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
gridList.Columns(0).Visible = False
gridList.Columns(1).SortExpression = ""
gridList.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

...

If my datagrid Allowsorting=true, then the code run error,but if I
config the Allowsorting=false, then above code run fine.
Please help me how to export if my datagrid has the allowsorting
properity.

Any help welcomes.

Best Regards,
Eric.

Nov 17 '05 #4
CJM
He can probably tell you how to set your clock...
Nov 17 '05 #5
Here's how... Go to the first message that you post dated. Then from the
Message menu in OE, choose Block Sender.

"Eric" <Er******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Would you like to tell me how to do?
Thanks.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netRemuvThis> дÈëÏûÏ¢ ÐÂÎÅ:Od*************@TK2MSFTNGP11.phx.gbl...
In this instance, since you know what the user wants when you query the
data, I would consider sorting the data on the server when you pull the
data. I am not sure why it bombs (I would have to examine the HTML
produced), but it is easily solved by sorting on the Data tier and

avoiding
the issue on the Presentation tier.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Author: ADO.NET and XML: ASP.NET on the Edge

************************************************** **************************
****
Think Outside the Box!

************************************************** **************************
****
"Eric" <Er******@hotmail.com> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
Dear All,

I want to export datagrid content to a Excel file, the code just like below:

Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
gridList.Columns(0).Visible = False
gridList.Columns(1).SortExpression = ""
gridList.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

...

If my datagrid Allowsorting=true, then the code run error,but if I
config the Allowsorting=false, then above code run fine.
Please help me how to export if my datagrid has the allowsorting
properity.

Any help welcomes.

Best Regards,
Eric.


Nov 17 '05 #6
hi eric,

are you getting some error like 'link item must be placed into form tag with an attribute runat=server" if so then your problem is because of when you use htmltextwriter and render control into it where your grids sorting property set to true then link items generate this error because your htmltextwriter doesn't include form tag.try including some form tag into htmltextwriter or , first disable allowsorting property to false , then export to excel and then rebind your dataset with allowsorting set to true (also this has some side effects where grid losts page numbers. etc)

regards,
ersin gen?t¨¹rk
"Eric" <Er******@hotmail.com> wrote in message news:uE**************@TK2MSFTNGP10.phx.gbl...
Dear All,

I want to export datagrid content to a Excel file, the code just like below:

Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
gridList.Columns(0).Visible = False
gridList.Columns(1).SortExpression = ""
gridList.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

...

If my datagrid Allowsorting=true, then the code run error,but if I config the Allowsorting=false, then above code run fine.
Please help me how to export if my datagrid has the allowsorting properity.

Any help welcomes.

Best Regards,
Eric.
Nov 17 '05 #7

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

Similar topics

3
by: Bidarkota | last post by:
When i export DataGrid to Excel all the HTML contents are also exporting to excel. i am using stylesheets in the ASPX Page and i am getting an alert message that stylesheets are missing. i need to...
1
by: Ed Chiu | last post by:
Hi, I copied the following codes from Internet to export datagrid to Excel, it works with datagrid not supporting sorting or paging. Response.ContentType = "application/vnd.ms-excel"...
0
by: jhgonzales | last post by:
The datagrid is exporting but without the images. When the file is downloaded, it seems that the excel file was supposed to have the images because they appear as "broken" image in the file. ...
5
by: The Colonel | last post by:
I'm only getting current page. I've tried playing with the PageSize and AllowPaging = False before exporting, but no luck. Here's my code: <snip> Public Sub btnExport_OnClick(ByVal sender...
8
by: chreo | last post by:
I would like to export earnigs of employees from datagrid to EXCEL. for example: __________________________ |..name.............|..money...............| -----------------------------------...
6
by: Sridhar | last post by:
Hi, I have to export data inside the datagrid into an excel worksheet. I have to do this on button click event. I am trying to do like this. First get the DataTable from the datagrid and...
3
by: Mike | last post by:
Hello, I am attempting to export the contents of a datagrid on my webform (using Excel automation) through ASP.NET. I have added the Excel object library to my VS ASP.NET project but I am...
0
by: madhavit | last post by:
hi, i am able to export datagrid data to excel sheet but the problem is i am not able to export datagrid within datagrid data to excel. can anybody help me. thanx.
2
by: leena13 | last post by:
Hi, The number of rows in the datagrid on my page are approx. around 14130. When I click on the button that exports the records to excel sheet, the page goes blank (I observed that none of the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.