使用DataPager for Datalist?

时间:2010-08-31 00:48:32

标签: c# asp.net datalist datapager

我们可以将DataPager用于DataList吗? 我已经完成了,但发生了以下异常!!!

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 

[InvalidOperationException: Control 'DataList1' does not implement IPageableItemContainer.]
   System.Web.UI.WebControls.DataPager.FindPageableItemContainer() +500609
   System.Web.UI.WebControls.DataPager.OnInit(EventArgs e) +33
   System.Web.UI.Control.InitRecursive(Control namingContainer) +333
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378

1 个答案:

答案 0 :(得分:1)

DataPager需要分页控件来实现IPageableItemContainer接口。该接口已在3.5中引入,因此旧控件不实现此接口。

解决方法可以是创建一个实现此接口的虚拟控件,并根据用于数据列表的数据源提供必要的分页逻辑。

编辑:顺便说一句,你总是可以使用ListView控件而不是DataList。