Previous Thread:   DetailsView Data Binding

9/30/2005 2:14:50 PM    how can I export ALL datagrid rows to excel?
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)  
  
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").GetValue(control, Nothing))  
  
control.Parent.Controls.Remove(control)  
  
End If  
  
End If  
  
End If  
  
End Sub  
  
</snip>



9/30/2005 11:34:46 PM    Re: how can I export ALL datagrid rows to excel?
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" <colonelangus@budweiser.com> wrote in message  
  
news:1128114890.628196.214220@o13g2000cwo.googlegroups.com...

9/30/2005 11:37:28 PM    Re: how can I export ALL datagrid rows to excel?
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" <colonelangus@budweiser.com> wrote in message  
  
news:1128114890.628196.214220@o13g2000cwo.googlegroups.com...

10/3/2005 9:37:36 AM    Re: how can I export ALL datagrid rows to excel?
Thanks Mr N. - what would that look like?

10/3/2005 9:40:27 AM    Re: how can I export ALL datagrid rows to excel?
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.

10/3/2005 10:40:41 AM    Re: how can I export ALL datagrid rows to excel?
Got it - I was turning off AllowPaging, but I needed to rebind after  
  
that!