473,508 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

export ALL datagrid rows to excel (not just current page)?

Any way to get it to export ALL rows? I tried playing with the
PageSize and AllowPaging = False before exporting, but no luck.

<snip>

Public Sub btnExport_OnClick(ByVal sender As Object, ByVal e As
EventArgs)
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=" &
gstrTableName & ".xls")
Response.Charset = ""
Me.EnableViewState = False
ClearControls(dgParent)
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
dgParent.PageSize =
gobjDataSet.Tables(gstrTableName).Rows.Count
dgParent.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
End Sub
Private Sub ClearControls(ByVal control As Control)
Dim i As Integer
For i = control.Controls.Count - 1 To 0 Step -1
ClearControls(control.Controls(i))
Next
If Not TypeOf control Is TableCell Then
If Not (control.GetType().GetProperty("SelectedItem") Is
Nothing) Then
Dim literal As New LiteralControl
control.Parent.Controls.Add(literal)
Try
literal.Text =
CStr(control.GetType().GetProperty("SelectedItem") .GetValue(control,
Nothing))
Catch
End Try
control.Parent.Controls.Remove(control)
Else
If Not (control.GetType().GetProperty("Text") Is
Nothing) Then
Dim literal As New LiteralControl
control.Parent.Controls.Add(literal)
literal.Text =
CStr(control.GetType().GetProperty("Text").GetValu e(control, Nothing))
control.Parent.Controls.Remove(control)
End If
End If
End If
End Sub
</snip>

Nov 19 '05 #1
1 1109
Anyone?

Nov 19 '05 #2

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

Similar topics

1
403
by: Diego | last post by:
Hi, I have a ASP.NET application and i'm interested in reporting in excel format. I read a good artile written by Steve C. Orr that gave me info about exporting to excel. ...
3
1654
by: mattdaddym | last post by:
Hi all, I have been using the following code to export my datagrids to excel for quite some time. Very simple and very effective. <code> Sub btnExcelExport_Click ( s As Object, e As...
5
2317
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...
6
3710
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...
4
3916
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
4
2179
by: Amirallia | last post by:
Hello Here's my code to export a datagrid to Exel : Response.Clear() Response.Buffer = True Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Dim monStringWriter As...
0
2727
by: Y2KPRABU | last post by:
for exporting to excel just call the function below in sample code and pass the page object from an aspx and the aspx page contents are rendered in excel.. make control.visible = false if you...
2
1762
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...
1
6664
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
0
7225
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
7123
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
7324
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
7382
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...
1
7042
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
5627
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,...
1
5052
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...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
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 ...

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.