Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Dave Bailey via DotNetMonster.com #1
problem exporting datagrid to excel
I am using the following code to export a datagrid to excel from an asp
page:
private void exportButton_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
hw.RenderBeginTag(System.Web.UI.HtmlTextWriterTag. Html);
this.ClearControls(reportGrid);
reportGrid.RenderControl(hw);
hw.RenderEndTag();
Response.Write(tw);
Response.End();
}
When I run this code I only get the first column returned to the
spreadsheet.
The is no other control on the datagrid so I am at a loss. Any suggestions
would be appreciated.
Thanks,
Dave
--
Message posted via [url]http://www.dotnetmonster.com[/url]
Dave Bailey via DotNetMonster.com Guest
-
Problem transfering datagrid to Excel
Hi, I have read a lot of articles in this newsgroup about how to solve this problem but found no solution. I'm trying to export a C# datagrid to... -
Handling special characters when exporting DataGrid to Excel
I am trying to export a DataGrid to Excel using a HtmlTextWriter and the DataGrid.RenderControl method. Everything is working fine except that... -
exporting a datagrid to excel
Can anyone tell me how to export data contained in a datagrid to excel using MC++? -------------------------------- From: Jonathan McMorris ... -
Datagrid to Excel Export Problem while adding summation values
We are getting a strange problem in exporting data grid to excel. We have a data grid in hand with basic data bounded to it and adding some... -
exporting webpage to excel formatting problem
Hi, I have a webpage that is taking input from a form and using it as criteria to select data out of an sql database. The page displays an html... -
ajamrozek #2
Re: problem exporting datagrid to excel
I'm not too sure how to solve your problem.
I store the dataset, filters, sorts and pageindex of the datagrid in
httpcache and session vars and then create a new datagrid using those
stored objects. I then use that for my Excel output.
It's in vb (easily translatable to c#, but I'm not gonna do it for you,
sorry)
Private Sub ExcelOut()
Page.Response.Clear()
Page.Response.AppendHeader("Content-Disposition",
"attachment; filename=")
Page.Response.ContentType = "application/vnd.ms-excel"
'Response.ContentType = "text/csv"
' Remove the charset from the Content-Type header.
Page.Response.Charset = ""
Dim dsAPL As DataSet =
MyCustomClass.DataAccess.SQLDataSet(_strDataContex t, "dbo." &
_strDataContext & "_GET", True), _
ds As DataSet = New DataSet
ds = dsAPL.Clone
ds.Merge(dsAPL)
If Not Page.Session(_strDataContext & "_Filter") Is Nothing
Then
ds.Tables(0).DefaultView.RowFilter =
Page.Session(_strDataContext & "_Filter")
End If
If Not Page.Session(_strDataContext & "_Sort") Is Nothing
Then
ds.Tables(0).DefaultView.Sort =
Page.Session(_strDataContext & "_Sort")
End If
Dim oItem As ListItem
For Each oItem In lstDisplayFields.Items
If Not oItem.Selected Then
ds.Tables(0).Columns.Remove(oItem.Value)
End If
Next
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim dgGrid As New DataGrid
dgGrid.DataSource = ds.Tables(0).DefaultView
dgGrid.DataBind()
' Get the HTML for the control.
dgGrid.RenderControl(hw)
' Write the HTML back to the browser.
Page.Response.Write(tw.ToString())
' End the response.
Page.Response.End()
ds.Dispose()
ds = Nothing
End Sub
ajamrozek Guest
-



Reply With Quote


