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

T

The Colonel

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").GetValue(control, Nothing))
control.Parent.Controls.Remove(control)
End If
End If
End If


End Sub


</snip>
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top