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

T

The Colonel

Man this export was easy to setup, but it only exports the current
page. Any way to get it to export ALL rows? I tried playing with the
PageSize 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").GetValue(control, Nothing))
control.Parent.Controls.Remove(control)
End If
End If
End If

End Sub

</snip>
 
T

The Colonel

Thanks, Jack - but that didn't do it. I placed it right before the
RenderControl with no success (still getting current page). It's Excel
2003.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top