ContentPlaceHolder必须放在具有 runat=server 的窗体标记内
生活随笔
收集整理的這篇文章主要介紹了
ContentPlaceHolder必须放在具有 runat=server 的窗体标记内
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
類型“GridView”的控件“ctl00_contentBody_gridView4Export”必須放在具有 runat=server 的窗體標記內。
?頁面是從母版頁繼承的,而gridview所在的ContentPlaceHolder確定是放在form中的。
以前只有控件未放在form中才會拋出同類異常。
?2?????{
?3?????????//?get?dataset
?4?????????SRMReportService.ReportService?srv?=?ServiceFactory.ReportService();
?5?????????DataSet?ds?=?srv.QueryAllData_Vendor_CheckAmount_Summary(
?6?????????????(string)this.ViewState["PlantCode"],
?7?????????????(string)this.ViewState["PeriodCode"],
?8?????????????(string)this.ViewState["VendorCode"]);
?9?
10?????????//?bind?to?gridview
11?????????this.gridView4Export.DataSource?=?ds;
12?????????this.gridView4Export.DataBind();
13?
14?????????//?export
15?????????this.ExportToExcel(this.gridView4Export);
16?????}
17?
18?
19?
20?
21?????public?void?ExportToExcel(System.Web.UI.Control?ctl)
22?????{
23?
24?????????Response.AppendHeader("Content-Disposition",?
25?????????????"attachment;filename=Excel.xls");
26?????????Response.ContentEncoding?=?
27?????????????System.Text.Encoding.GetEncoding("GB2312");
28?????????Response.ContentType?=?"application/ms-excel";
29?????????
30?????????System.Globalization.CultureInfo?myCItrad?=?
31?????????????new?System.Globalization.CultureInfo("ZH-CN",?true);
32?????????System.IO.StringWriter?tw?=?
33?????????????new?System.IO.StringWriter(myCItrad);
34?????????try
35?????????{
36?????????????System.Web.UI.HtmlTextWriter?hw?=?new?HtmlTextWriter(tw);
37?????????????ctl.RenderControl(hw);
38?????????????Response.Write(tw.ToString());
39?????????????Response.End();
40?????????}
41?????????finally
42?????????{
43?????????????tw.Close();
44?????????}
45?????}
46?
在您的codebehind文件中,繼承自page基類的那個頁面類中復制如下代碼進去:
??? public override void VerifyRenderingInServerForm(Control control)
??? {
??????? // Confirms that an HtmlForm control is rendered for
??? }
轉載于:https://www.cnblogs.com/rooney/archive/2008/08/13/1267045.html
總結
以上是生活随笔為你收集整理的ContentPlaceHolder必须放在具有 runat=server 的窗体标记内的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AutoCAD.net: DXF群码
- 下一篇: Photoshop简单制作绿色暗调风景图