|
| Export data from datagrid to Excel |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.framework.aspnet.datagridcontrol.
| Mary |
The examples I found online of exporting data from a web page to Excel either display the data in Excel from the page_load event or write the data to an excel file and e-mail it to the user. I want to do this from a button click event.
I display data in a datagrid and have a dropdownlist (server control) with a go button below it where users can choose to export data to Excel, MS Word, or text. When the user clicks the go button an OnServerClick event is triggered and the aspx.vb code is called to respond to the event. I can't get the event handler code to display the data in an Excel spreadsheet. A blank window is displayed. Anybody have any thoughts on what I should do???? Thanks for any help.
This is the code (modified slightly from an MSDN article on exporting datagrid data from the page_load event):
Protected Sub btnExport_onServerClick(ByVal Sender As Object, ByVal E As EventArgs) _
Handles btnExport.Click
' Excel Export code
Dim strResult As String = Request("ddlExport_Options")
If strResult = "Excel" Then
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
ElseIf strResult = "MS Word" Then
' Set the content type to MSWord.
Response.ContentType = "application/msword"
ElseIf strResult = "Text" Then
' Set the content type to MSWord.
Response.ContentType = "text/plain"
End If
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
dgrORF.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
End Sub
|
|
|
| |
|
| |
| |
| Harry Simpson |
Mary,
Try this: button opens new window with another aspx within it.
Export to Excel
***************************************
<INPUT style="Z-INDEX: 117; LEFT: 604px; WIDTH: 73px; POSITION: absolute; TOP: 449px; HEIGHT: 24px" onclick="DoClick()" type="button" value="Export">
**************************************
function DoClick()
{
window.open('LoadXLS.aspx','MyWindow','width=500,height=500');
}
**************************************
LoadXLS.aspx code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
'Me.EnableViewState = False
Dim dsExport As DataSet = Session("dsExport")
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim dgGrid As New DataGrid()
dgGrid.DataSource = dsExport
dgGrid.DataBind()
'dgGrid = Session("GridExport")
' Get the HTML for the control.
dgGrid.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
End Sub
You could probably do it any number of ways though.
HTH
Harry
"Mary" <Click here to reveal e-mail address> wrote in message news:ekAfCL$NCHA.1256@tkmsftngp13... [Original message clipped]
|
|
|
| |
|
| |
| |
| estagio sunviauto |
I do this, and works. The problem is that i use the css and then dont write the name of the textbox (textbox1.rendercontrol(h)) but write the css line. why?
|
|
|
| |
|
|
| |
|
|
| |
| yamini |
(Type your message here)
Even i was trying to export data from datagrid to excel. I tried this coding, but this doesn't work for me, since my datagrid has paging and sorting option. I am not able to solve this problem, if any one knows how to solve this, plz suggest me.Thanks. -------------------------------- From: yamini
|
|
|
| |
|
| |
| |
| Praveen Jhurani |
Were you able to figure this one or get an answer on exporting datagrid with paging option enabled.
-------------------------------- From: Praveen Jhurani
|
|
|
| |
|
| |
|
| |
| Rishi Bhushan |
(Type your message here)
-------------------------------- From: Rishi Bhushan
|
|
|
| |
|
|
| |
|
| |
| Rishi Bhushan |
Even i was trying to export data from datagrid to excel. I tried this coding, but this doesn't work for me, since my datagrid has paging and sorting option. I am not able to solve this problem, if any one knows how to solve this, plz suggest me.Thanks.
-------------------------------- From: Rishi Bhushan
|
|
|
| |
|
| |
|
|
| |
| Manish Kaushik |
Hi Friends
How can i do the same if i have to export the data of the datagrid control in VB.net form in windows 2000 platform
Please guide me
-------------------------------- From: Manish Kaushik
|
|
|
| |
|
| |
|
| |
| Guillermo ?lvarez |
I export data from datagrid yo excel. Ok. But then I can't save the document into an excel file because in the window doesn't appear any menu bar. Can you help me? Thanks
-------------------------------- From: Guillermo ?lvarez
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|