close

    public override void VerifyRenderingInServerForm(Control control)
    {
        //required to avoid the runtime error "
        //Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
    }

    private void ExportGridToExcel()
    {        
        Response.Clear();
        Response.Buffer = true;
        Response.ClearContent();
        Response.ClearHeaders();
        Response.Charset = "";
        string FileName = DateTime.Now.ToString("yyyy_MM_dd") + ".xls";
        StringWriter strwritter = new StringWriter();
        HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.ms-excel";
        Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
        GV_DataReport.GridLines = GridLines.Both;
        GV_DataReport.HeaderStyle.Font.Bold = true;
        GV_DataReport.RenderControl(htmltextwrtter);
        Response.Write(strwritter.ToString());
        Response.End();
    }

arrow
arrow
    創作者介紹
    創作者 芭樂養樂多 的頭像
    芭樂養樂多

    隨手筆記

    芭樂養樂多 發表在 痞客邦 留言(0) 人氣()