DataGrid1中嵌套着DataGrid2
在DataGrid2中又有Button1是用下面的方法导出会出错:
Exception Details: System.Web.HttpException: Control 'DataGrid1__ctl2__Button1' of type 'Button' must be placed inside a form tag with runat=server.
有没有什么解决办法啊??????????????????Response.Clear(); 
Response.Buffer= true; 
Response.Charset="GB2312";    
Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls"); 
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/vnd.ms-excel";//设置输出文件类型为excel文件。 
this.EnableViewState = false;  
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); 
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.DataGrid1.RenderControl(oHtmlTextWriter); 
Response.Write(oStringWriter.ToString());
Response.End();

解决方案 »

  1.   

    应该是你的button没有加runat=server
      

  2.   

    直接RenderControl不行,
    动态构造结果Table,然后TableRenderControl!
      

  3.   

    就是不嵌套DataGrid1,如果里面有服务器控件也会报这样的错误!
      

  4.   

    暂时在导出前循环每个DataGridItem项,把报错Control的Visable设成False
    不知道还有没有其他的解决方法???
      

  5.   

    看看这个,能不能对你有所帮助
    http://www.cnblogs.com/singlepine/archive/2006/01/07/312975.html
      

  6.   

    问题暂时解决了。
    我在导出之前把button出去了。