In web application most of the we display the data in grid and provide the facility to export it to excel. We have lots of method for this. One of the method is render the grid in to html and open it in to excel.
Code:
gridView1.DataSource = dsEmployee.tables(0)
Me.gridView1.DataBind()
' 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 tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
'DataGrid1.RenderControl(hw)
'Render the grid.
gridView1.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
By above code you can export the data to excel.
But some time when we render the grid we face problem like :
"Control 'gridView1' of type 'GridView' must be placed inside a form tag with runat=server"
Add following code in you page :
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
' Confirms that an HtmlForm control is rendered for the
' specified ASP.NET server control at run time.
' No code required here.
End Sub
That code solve my problem. Hope same for you Guys.
Wednesday, January 28, 2009
Sunday, January 25, 2009
Use AJAX with check box in Gridview to avoid postback.
If you have check box in your grid, it is better to use AJAX. It will give you a cool look to your page.
How we can use? Wait i am coming with source code.
How we can use? Wait i am coming with source code.
Subscribe to:
Posts (Atom)