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();
在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();
动态构造结果Table,然后TableRenderControl!
不知道还有没有其他的解决方法???
http://www.cnblogs.com/singlepine/archive/2006/01/07/312975.html
我在导出之前把button出去了。