Exporting to Excel directly from ObjectDataSource?

  • Thread starter Thread starter ASF
  • Start date Start date
A

ASF

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?
 
Hi Steve,

Your articles are informative, but you may have misunderstood my
question. I want to pull directly from the objectdatasource to excel
but I haven't discerned how to access the ODS datatable in the
codebehind. Thoughts?

Thanks
 
Back
Top