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_OnCli ck(ByVal sender As Object, ByVal e As
EventArgs)
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-Disposition", "inline;filenam e=" &
gstrTableName & ".xls")
Response.Charse t = ""
Me.EnableViewSt ate = False
ClearControls(d gParent)
Dim tw As New System.IO.Strin gWriter
Dim hw As New System.Web.UI.H tmlTextWriter(t w)
' Get the HTML for the control.
dgParent.PageSi ze =
gobjDataSet.Tab les(gstrTableNa me).Rows.Count
dgParent.Render Control(hw)
' Write the HTML back to the browser.
Response.Write( tw.ToString())
' End the response.
Response.End()
End Sub
Private Sub ClearControls(B yVal control As Control)
Dim i As Integer
For i = control.Control s.Count - 1 To 0 Step -1
ClearControls(c ontrol.Controls (i))
Next
If Not TypeOf control Is TableCell Then
If Not (control.GetTyp e().GetProperty ("SelectedItem" ) Is
Nothing) Then
Dim literal As New LiteralControl
control.Parent. Controls.Add(li teral)
Try
literal.Text =
CStr(control.Ge tType().GetProp erty("SelectedI tem").GetValue( control,
Nothing))
Catch
End Try
control.Parent. Controls.Remove (control)
Else
If Not (control.GetTyp e().GetProperty ("Text") Is
Nothing) Then
Dim literal As New LiteralControl
control.Parent. Controls.Add(li teral)
literal.Text =
CStr(control.Ge tType().GetProp erty("Text").Ge tValue(control, Nothing))
control.Parent. Controls.Remove (control)
End If
End If
End If
End Sub
</snip> 5 2322
I guess Im too tired to really give much here, but the the first question is
why you are not using the object to which the DataGrid is bound to export
from, rather than the grid itself ?
Regards - Mr N ( Who is off to sleep now )
"The Colonel" <co**********@b udweiser.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. . 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_OnCli ck(ByVal sender As Object, ByVal e As EventArgs)
Response.Conten tType = "applicatio n/vnd.ms-excel" Response.AddHea der("Content-Disposition", "inline;filenam e=" & gstrTableName & ".xls") Response.Charse t = ""
Me.EnableViewSt ate = False ClearControls(d gParent)
Dim tw As New System.IO.Strin gWriter Dim hw As New System.Web.UI.H tmlTextWriter(t w)
' Get the HTML for the control. dgParent.PageSi ze = gobjDataSet.Tab les(gstrTableNa me).Rows.Count dgParent.Render Control(hw)
' Write the HTML back to the browser. Response.Write( tw.ToString())
' End the response. Response.End()
End Sub
Private Sub ClearControls(B yVal control As Control)
Dim i As Integer For i = control.Control s.Count - 1 To 0 Step -1 ClearControls(c ontrol.Controls (i)) Next
If Not TypeOf control Is TableCell Then If Not (control.GetTyp e().GetProperty ("SelectedItem" ) Is Nothing) Then Dim literal As New LiteralControl control.Parent. Controls.Add(li teral) Try literal.Text = CStr(control.Ge tType().GetProp erty("SelectedI tem").GetValue( control, Nothing)) Catch End Try control.Parent. Controls.Remove (control) Else If Not (control.GetTyp e().GetProperty ("Text") Is Nothing) Then Dim literal As New LiteralControl control.Parent. Controls.Add(li teral) literal.Text = CStr(control.Ge tType().GetProp erty("Text").Ge tValue(control, Nothing)) control.Parent. Controls.Remove (control) End If End If End If
End Sub
</snip>
I have an example of this on my website, www.aboutfortunate.com, (your code
is very close). Click on the "Code Library" link at the top of the page and
then click on the datagrid row "Ouput a datagrid as an excel spreadsheet
page".
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"The Colonel" <co**********@b udweiser.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. . 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_OnCli ck(ByVal sender As Object, ByVal e As EventArgs)
Response.Conten tType = "applicatio n/vnd.ms-excel" Response.AddHea der("Content-Disposition", "inline;filenam e=" & gstrTableName & ".xls") Response.Charse t = ""
Me.EnableViewSt ate = False ClearControls(d gParent)
Dim tw As New System.IO.Strin gWriter Dim hw As New System.Web.UI.H tmlTextWriter(t w)
' Get the HTML for the control. dgParent.PageSi ze = gobjDataSet.Tab les(gstrTableNa me).Rows.Count dgParent.Render Control(hw)
' Write the HTML back to the browser. Response.Write( tw.ToString())
' End the response. Response.End()
End Sub
Private Sub ClearControls(B yVal control As Control)
Dim i As Integer For i = control.Control s.Count - 1 To 0 Step -1 ClearControls(c ontrol.Controls (i)) Next
If Not TypeOf control Is TableCell Then If Not (control.GetTyp e().GetProperty ("SelectedItem" ) Is Nothing) Then Dim literal As New LiteralControl control.Parent. Controls.Add(li teral) Try literal.Text = CStr(control.Ge tType().GetProp erty("SelectedI tem").GetValue( control, Nothing)) Catch End Try control.Parent. Controls.Remove (control) Else If Not (control.GetTyp e().GetProperty ("Text") Is Nothing) Then Dim literal As New LiteralControl control.Parent. Controls.Add(li teral) literal.Text = CStr(control.Ge tType().GetProp erty("Text").Ge tValue(control, Nothing)) control.Parent. Controls.Remove (control) End If End If End If
End Sub
</snip>
Thanks Mr N. - what would that look like?
Thanks, Justin. It is very close - I guess the only difference is that
I'm displaying the grid with an export button, so the export is
actually taking place in an OnClick sub. I'll probably have to go a
different route.
Got it - I was turning off AllowPaging, but I needed to rebind after
that! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Maria L. |
last post by:
Hi,
I need to export the content of a DataGrid (in Windows application in C#), into
an Excel spreadsheet.
Anyone knows how to do this? Any code snippets would help!
thanks a lot,
Maria
|
by: sunilkumar Reddy via DotNetMonster.com |
last post by:
hai all
first we can take binded grid
Export to excel data from ultrawebgrid (or) datagrid rows,
Each row data Expoting to one worksheet in excel workbook,
like as
grid row1 data contain sheet1
grid row2 data contain sheet2
grid row3 data contain sheet3
we have pressing one button ultrawebgrid (or) datagrid rows data to export
|
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.
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp
Basically the app shows the report in a datagrid and on the OnClick event of
|
by: DC Gringo |
last post by:
I have a simple button that should open another window and export a datagrid
to an Excel file. I'm getting: "Name 'window' is not declared."
What do I need to declare or import?
<INPUT ID="Button5" ONCLICK="Button5_Click" NAME="Button5" TYPE="button"
VALUE="Export to Excel">
Sub Button5_Click()
|
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 EventArgs )
Response.Clear()
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls")
| |
by: sunilkumar Reddy via DotNetMonster.com |
last post by:
hai all
first we have taken binded grid
Export to excel data from ultrawebgrid (or) datagrid rows,
Each row data Expoting to one worksheet in excel workbook,
like as
grid row1 data contain sheet1
grid row2 data contain sheet2
grid row3 data contain sheet3
we have pressing one button ultrawebgrid (or) datagrid rows data to export
|
by: kieran |
last post by:
Hi,
I have an 'export to excel' button on my Datagrid. All works well
except that on my Datagrid, I have sub total rows. The subtotal rows
use colspan so that the subtotals are given above certain columns
When I export to excel, I do not have the colspan. As a result, the
subtotals appear over the wrong columns in Excel.
|
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 StringWriter = New StringWriter
Dim monHtmlTextWriter As HtmlTextWriter = New
HtmlTextWriter(monStringWriter)
|
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...
|
by: hemantbasva |
last post by:
Note We need to have a template on server for generating report in multiple sheet
as we do not had msoffice on server
moreover this require a batch job to delete excel file created by the method....
it creates 6 sheets
# region Namespaces
using System;
|
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’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, and deployment—without 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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |