Exporting to Excel directly from ObjectDataSource?



Hey all,
I have a gridview with an objectdatasource. I've been using the below
code to export to excel:

gvITV.AllowSorting = False
gvITV.DataBind()
Dim tw As New IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim frm As HtmlForm = New HtmlForm()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition",
"attachment;filename=export.xls")
Response.Charset = ""
EnableViewState = False
Controls.Add(frm)
frm.Controls.Add(gvITV)
frm.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
gvITV.AllowSorting = True
gvITV.DataBind()

However, I dislike that I have to pull from the Gridview at all. I
should be able to skip the gridview binding and pull directly from the
objectdatasource, but I haven't been able to discover a way to do
this. Does anyone have any suggestions?
.



Relevant Pages

  • RE: DataGridView with databound combobox
    ... "'cboActivityTime' has a SelectedValue which is invalid because it does not ... My ObjectDatasource ... In the GridView RowEditing Event I can easily get hold of the Literal ... Dim row As GridViewRow ...
    (microsoft.public.dotnet.framework.aspnet)
  • .NET 2.0 Delete using GridView and ObjectDataSource
    ... connection) ... Dim list As New Generic.List ... the GridView has no DataKeyNames attribute set. ... DataObjectTypeName property in ObjectDataSource 'ObjectDataSource1'. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Gridview to XLS... formatting issues
    ... > excel spreadsheet. ... > Dim tw As New System.IO.StringWriter ... > Dim frm As HtmlForm = New HtmlForm ... > Now it all works great, however in the gridview I have some text fields ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Exporting to Excel directly from ObjectDataSource?
    ... I've documented a number of ways to export data to Excel: ... Dim tw As New IO.StringWriter ... Dim frm As HtmlForm = New HtmlForm ... I dislike that I have to pull from the Gridview at all. ...
    (microsoft.public.dotnet.framework.aspnet)
  • conditional formatting of text in a gridview
    ... I was looking to format the text of certain values in my gridview, ... If I don't use an ObjectDataSource - but instead manually populate the ... Dim strSBP As String = e.Row.Cells.Text ... Dim iSBP, iDBP, iSBPTarget, iDBPTarget As Integer ...
    (microsoft.public.dotnet.framework.aspnet)