当前位置:编程学习 > C#/ASP.NET >>

紧急求助导出到excel乱码

从页面上导出gridview1到excel,数据源的sql用select * from temp where xh<3
导出正常显示汉字,sql用select * from temp where xh in (1,2,3) 导出到excel
却显示乱码,真是奇怪,百思不得其解,数据库是sql_server2000
试了几次用select * from temp where xh=3也不行

--------------------编程问答--------------------  protected void outport_Click(object sender, EventArgs e)
    {
        Export("application/ms-excel", DropDownList1.SelectedValue );
    }
    private void Export(string FileType, string FileName)
    {
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        GV_cg.RenderControl(hw);
        //DataList1.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    } --------------------编程问答-------------------- 正解 --------------------编程问答--------------------
引用 1 楼 jasondct 的回复:
protected void outport_Click(object sender, EventArgs e) 
    { 
        Export("application/ms-excel", DropDownList1.SelectedValue ); 
    } 
    private void Export(string FileType, string FileName) 
    { 
        Response.Charset = "GB2312"; 
        Response.ContentEncoding = System.Text.Encoding.UTF7; 
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + Ht…

正解 --------------------编程问答-------------------- 有答案了就不多说了
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,