Link to home
Start Free TrialLog in
Avatar of westdh
westdhFlag for United States of America

asked on

export gridvie to exle

How do I export a grid to excel
Avatar of five22bags
five22bags
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of Kumaraswamy R
Kumaraswamy R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi..
Create a Seperate Class File.. and just call the function in your code behind
i have mentioned the Class file coding in the Below URL of Experts-Exchange..

hope this will help you surely..

https://www.experts-exchange.com/questions/24844004/export-to-excel.html
try following code ..
Public Shared Sub ExportGridToExcel(ByVal grdGridView As GridView, ByVal fileName As String)
        Current.Response.Clear()
        Current.Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.xls", fileName))
        Current.Response.Charset = ""
        ' Current.Response.ContentType = "application/vnd.xls";
        Dim stringWrite As New StringWriter()
        Dim htmlWrite As New HtmlTextWriter(stringWrite)
        grdGridView.RenderControl(htmlWrite)
        Current.Response.Write(stringWrite.ToString())
        Current.Response.Flush()
        Current.Response.[End]()
    End Sub


and just pass the grid name  and the filename thats all..