返回首页

Response.Write("Export to excel");

        Response.Clear();

        Response.Charset = "";

        

        Response.ContentType = "application/vnd.ms-excel";

        Response.AddHeader("content-disposition", "attachment;filename=Demo.xls");

        Response.Charset = "";

        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        StringWriter stringwriter = new StringWriter();

        HtmlTextWriter htmwrite = new HtmlTextWriter(stringwriter);

        GridView1.RenderControl(htmwrite);

        Response.Write(stringwriter.ToString());

        Response.End();

 

This  is my code to export gridview to excel. but an error is shown as

Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

Pls help me to correct this

回答

评论会员:游客 时间:2012/02/06
imgsrc=]应该帮助你
乌玛・尚卡尔帕特尔
评论会员:游客 时间:2012/02/06
检查您的设计代码,把里面的形式标记或与RUNAT="服务器"的ContentPlaceHoldergridview1您可以使用另一种工具,同甲酸导出到Excel的GridView{A1}
member60
评论会员:reffer:{A2}] 时间:2012/02/06
shek124
评论会员:游客 时间:2012/02/06
添加这些代码在你的aspx页面{C}关于谢赫|SwingSwis
请参考以下链接:

{A3的}

{A4纸}]
评论会员:YogeshPednekar 时间:2012/02/06
第一aspx页面上拖动的GridView控件

然后添加按钮控制

<asp:Button onclick="Button1_Click" text="Export to Excel" runat="server" id="Button1"/>

并粘贴上。CS页代码
{体C3}
我希望做您的问题将解决。|