Exporting an unvisible datagrid to excel C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I've got a datagrid I want to export to excel, but do not want to display it on the webform. If I make it unvisible, it doesn't export the data in the datagrid. But if visible, it does export data. Do you know how I can still keep the datagrid unvisible, but be able to export the data?
 
Hello,
Why do you need to use datagrid, since you don't want to show it at all? You
can export data directly from the source with which this datagrid is bound.

--
Rami Saad
Microsoft GTSC Developer support for Middle East


Lisa said:
Hi,
I've got a datagrid I want to export to excel, but do not want to display
it on the webform. If I make it unvisible, it doesn't export the data in the
datagrid. But if visible, it does export data. Do you know how I can still
keep the datagrid unvisible, but be able to export the data?
 
Hi
I'm using the RenderControl method and it doesn't want to take a source. This is how I use it
System.IO.StringWriter SW = new System.IO.StringWriter()
System.Web.UI.HtmlTextWriter HT = new System.Web.UI.HtmlTextWriter(SW)
dgExport.RenderControl(HT); // Datagrid to export to exce
Response.Write(SW.ToString())
Response.End();
 
Back
Top