日期:2014-05-18  浏览次数:20569 次

俺是初学者,从网上找来的这段分页显示示例代码,运行报错??!!
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
<script runat="server" language="c#">
void Page_Load()
{
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection+=Server.MapPath("dbfile/db.mdb");
OleDbConnection objConnection=new OleDbConnection(strConnection);
OleDbDataAdapter objDataAdapter=new OleDbDataAdapter("select * from person",objConnection);
DataSet objDataSet=new DataSet();
objDataAdapter.Fill(objDataSet);
dgrdMain.DataSource=objDataSet;
dgrdMain.DataBind();
}
void dgrdMain_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e)
{
dgrdMain.CurrentPageIndex = e.NewPageIndex;
DataBind();
}
</script>
<html>
<body>
<asp:DataGrid id="dgrdMain" cellpadding="1" showheader="true" borderwidth="0" allowpaging="true" pagesize="3" onpageindexchanged="dgrdMain_PageIndexChanged " runat="server"/>
</body>
</html>


说明:这段代码每页显示条目数为3,当我的表中的条目数小于3的时候页面正常,超过3,也就是超出一页时候就会报错如下:
“/ASPNET”应用程序中的服务器错误。
--------------------------------------------

类型“DataGridLinkButton”的控件“dgrdMain_ctl07_ctl01”必须放在具有 runat=server 的窗体标记内。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Web.HttpException: 类型“DataGridLinkButton”的控件“dgrdMain_ctl07_ctl01”必须放在具有 runat=server 的窗体标记内。

源错误: 

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  

堆栈跟踪: 


[HttpException (0x80004005): 类型“DataGridLinkButton”的控件“dgrdMain_ctl07_ctl01”必须放在具有 runat=server 的窗体标记内。]
  System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +213
  System.Web.UI.WebControls.LinkButton.AddAttributesToRender(HtmlTextWriter writer) +37
  System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +17
  System.Web.UI.WebControls.DataGridLinkButton.Render(HtmlTextWriter writer) +25
  System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +53
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +294
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +24
  System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
  System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +21
  System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter writer) +97
  System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
  System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +53
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +294
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +24
  System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
  System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +21
  System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +7
  System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
  System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +53
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +294
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +24