Home » » Export DataGrid to Excel

Export DataGrid to Excel

Written By M.L on வியாழன், 4 ஆகஸ்ட், 2011 | ஆகஸ்ட் 04, 2011

Through mine functionality of ASP.Net, I could export all available data from Data Grid to Excel file but I need to write those data to a specific excel file which is located in Web folder. sample code I had given below for your better understanding


Response.Clear();
        Response.ClearContent();
        Response.Charset = "";
        Response.ContentType = "application/vnd,xls";
        Response.AppendHeader("content-disposition", "attachment; filename=Ex.xls");
        DataGrid1.DataSource = ExportTbl;

        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        DataGrid1.DataBind();
        DataGrid1.RenderControl(hw);
        Response.Write(sw.ToString());
        Response.End();

0 comments:

கருத்துரையிடுக

Popular Posts

General Category