datagrid导数据到excel中出错!解决就给分
类型“DataGridLinkButton”的控件“DGridUnemp__ctl14__ctl1”必须放在具有 runat=server 的窗体标记内。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Web.HttpException: 类型“DataGridLinkButton”的控件“DGridUnemp__ctl14__ctl1”必须放在具有 runat=server 的窗体标记内。
源错误:
行 395: System.IO.StringWriter tw = new System.IO.StringWriter() ;
行 396: System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
行 397: ctl.RenderControl(hw);
行 398: HttpContext.Current.Response.Write(tw.ToString());
行 399: HttpContext.Current.Response.End();
源文件: d:\inetpub\wwwroot\webwbinsurance\formunempinfocheck.aspx.cs 行: 397
源文件:
public void ToExcel(System.Web.UI.Control ctl)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");
HttpContext.Current.Response.Charset ="GB2312";
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.ContentType ="application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctl.Page.EnableViewState =false;
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}