I export the contents of my datagrid controls to Excel using the
following Sub:
Sub WriteToExcel(Sender as Object, E as EventArgs)
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition","attachment;filename=Data.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.No Cache)
Dim stringWrite As StringWriter = New StringWriter
Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
dstDataGrid.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
End Sub
This works great, but what I really need it to do is export the contents
of a datagrid on another page. The lefthand menu pane in all of my pages
is actually an ascx object that I import into them, so that it looks the
same on all pages and I only have to change one page when my menu pane
changes. Unfortunately the button that fires the above sub is on that
ascx object, so it's looking for, and not finding, a datagrid on itself,
not on the parent page.
The name of my datagrid can always be the same, if that helps. Can I get
the third-to-the-last line of my Sub to reach across to the parent
page and hook up with a datagrid there?
As always, thanks for any help.