Exporting to Excel directly from ObjectDataSource?


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?
 
Ad

Advertisements

S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

Ad

Advertisements

A

ASF

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
 

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

Top