473,706 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export datagrid(with allowsorting) to Excel

Dear All,

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

Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Me.EnableViewSt ate = False
Dim tw As New System.IO.Strin gWriter()
Dim hw As New System.Web.UI.H tmlTextWriter(t w)
gridList.Column s(0).Visible = False
gridList.Column s(1).SortExpres sion = ""
gridList.Render Control(hw)
Response.Write( tw.ToString())
Response.End()

....

If my datagrid Allowsorting=tr ue, then the code run error,but if I config the Allowsorting=fa lse, 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 5894
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******@hotma il.com> wrote in message
news:uE******** ******@TK2MSFTN GP10.phx.gbl...
Dear All,

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

Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Me.EnableViewSt ate = False
Dim tw As New System.IO.Strin gWriter()
Dim hw As New System.Web.UI.H tmlTextWriter(t w)
gridList.Column s(0).Visible = False
gridList.Column s(1).SortExpres sion = ""
gridList.Render Control(hw)
Response.Write( tw.ToString())
Response.End()

....

If my datagrid Allowsorting=tr ue, then the code run error,but if I
config the Allowsorting=fa lse, 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.netRem uvThis> wrote in
message news:Od******** *****@TK2MSFTNG P11.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******@hotma il.com> wrote in message
news:uE******** ******@TK2MSFTN GP10.phx.gbl...
Dear All,

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

Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Me.EnableViewSt ate = False
Dim tw As New System.IO.Strin gWriter()
Dim hw As New System.Web.UI.H tmlTextWriter(t w)
gridList.Column s(0).Visible = False
gridList.Column s(1).SortExpres sion = ""
gridList.Render Control(hw)
Response.Write( tw.ToString())
Response.End()

...

If my datagrid Allowsorting=tr ue, then the code run error,but if I
config the Allowsorting=fa lse, 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.netRem uvThis> 写入消息
新闻:Od******** *****@TK2MSFTNG P11.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******@hotma il.com> wrote in message
news:uE******** ******@TK2MSFTN GP10.phx.gbl...
Dear All,

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

Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Me.EnableViewSt ate = False
Dim tw As New System.IO.Strin gWriter()
Dim hw As New System.Web.UI.H tmlTextWriter(t w)
gridList.Column s(0).Visible = False
gridList.Column s(1).SortExpres sion = ""
gridList.Render Control(hw)
Response.Write( tw.ToString())
Response.End()

...

If my datagrid Allowsorting=tr ue, then the code run error,but if I
config the Allowsorting=fa lse, 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******@hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Would you like to tell me how to do?
Thanks.

"Cowboy (Gregory A. Beamer)" <No************ @comcast.netRem uvThis> 写入消息 新闻:Od******** *****@TK2MSFTNG P11.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******@hotma il.com> wrote in message
news:uE******** ******@TK2MSFTN GP10.phx.gbl...
Dear All,

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

Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Me.EnableViewSt ate = False
Dim tw As New System.IO.Strin gWriter()
Dim hw As New System.Web.UI.H tmlTextWriter(t w)
gridList.Column s(0).Visible = False
gridList.Column s(1).SortExpres sion = ""
gridList.Render Control(hw)
Response.Write( tw.ToString())
Response.End()

...

If my datagrid Allowsorting=tr ue, then the code run error,but if I
config the Allowsorting=fa lse, 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******@hotma il.com> wrote in message news:uE******** ******@TK2MSFTN GP10.phx.gbl...
Dear All,

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

Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Me.EnableViewSt ate = False
Dim tw As New System.IO.Strin gWriter()
Dim hw As New System.Web.UI.H tmlTextWriter(t w)
gridList.Column s(0).Visible = False
gridList.Column s(1).SortExpres sion = ""
gridList.Render Control(hw)
Response.Write( tw.ToString())
Response.End()

...

If my datagrid Allowsorting=tr ue, then the code run error,but if I config the Allowsorting=fa lse, 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
4352
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 export only the contents of the Datagrid to excel. i don't need all other stuff which is present on the page. is there any way to achieve it. Thanks in Advance
1
2131
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" Response.Charset = "" Response.AddHeader("Content-Disposition", "attachment;filename=Statement.xls") Me.EnableViewState = False
0
1168
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. This is the abbreviated approach that I am currently using. Response.Clear() Response.Buffer = True Response.ContentType = "application/vnd.ms-excel" Response.Charset = ""
5
2324
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 As Object, ByVal e As EventArgs)
8
4639
by: chreo | last post by:
I would like to export earnigs of employees from datagrid to EXCEL. for example: __________________________ |..name.............|..money...............| ----------------------------------- |..John..............|..100$.................| |..Mary.............|...150S...............| -----------------------------------
6
3729
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 iterate through each row to get the data. I am not able to get the DataTable from the datagrid. How could I do that? I tried like this but it is not working Dim dt as DataTable = CType(datagrid1.DataSource, DataTable)
3
1832
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 lost on how to export my datagrid contents to Excel? I am sure it can be done but having difficulties figuring out the code.
0
1473
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
1769
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 events are firing). To confirm this is happening because of the no. of rows, I modified the SP to retrieve around only 100 records. I could export these records in the datagrid successfully. I am aware that the max no of rows to export to excel...
0
8772
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we抣l explore What is ONU, What Is Router, ONU & Router抯 main usage, and What is the difference between ONU and Router. Let抯 take a closer look ! Part I. Meaning of...
0
9276
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9141
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7895
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梡lanning, coding, testing, and deployment梬ithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6607
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3140
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2084
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.