使用Datagridview导出到Excel不起作用 [英] Export To Excel using Datagridview not working

查看:68
本文介绍了使用Datagridview导出到Excel不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友
我正在尝试导出datagridview,但它不起作用.这是我的代码.

Hello Friends
i am trying to export datagridview but its not work . here is my code..

protected void BtnExcel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=OrderReports.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.xls";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GrdOrder.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();

    }




代码到我的网站成功运行,然后查看inspect元素,然后出现如下错误:-

未捕获的Sys.WebForms.PageRequestManagerParserErrorException:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息.导致此错误的常见原因是通过调用Response.Write(),响应筛选器,HttpModules或服务器跟踪来修改响应.
详细信息:解析错误''




code run successfully when i come to my website and see the inspect element then its give the error like this :-

Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near ''

推荐答案

解决方案mySelf


我只要将此代码添加到aspx页面中即可:-
Got the Solution mySelf


Me just add this code in aspx page:-
<Triggers>
            <asp:PostBackTrigger ControlID="BtnExcel" />
            <asp:PostBackTrigger ControlID="BtnWord" />
</Triggers>





谢谢大家... !!
祝你有美好的一天





Thank You all...!!
Have a nice day


这篇关于使用Datagridview导出到Excel不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆