【问题标题】:PagedDataSource not getting datasourcePagedDataSource 没有获取数据源
【发布时间】:2012-07-23 22:03:31
【问题描述】:

我无法让PagedDataSource 使用EntityCollection 对象的IEnumerated 集合作为数据源。

PagedDataSource 接受集合作为数据源,但我不能使用 CurrentPageIndexIsLastPage 等基本属性。

我的应用程序因错误 Cannot compute Count for a data source that does not implement ICollection. 而中断

我试过了

ICollection<Location> listlocations = Company.Locations;

但没有成功。

我能做什么?

代码sn-p

    protected void loadBuildings()
    {
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = Company.Locations;
        pds.AllowPaging = true;
        pds.PageSize = Convert.ToInt16(ddlPageSize.SelectedValue);
        pds.CurrentPageIndex = CurrentPage;
        lnkbtnNext.Enabled = !pds.IsLastPage;
        lnkbtnPrevious.Enabled = !pds.IsFirstPage;

        buildingsDataList.DataSource = pds;
        buildingsDataList.DataBind();
    }

【问题讨论】:

    标签: c# datasource icollection entitycollection


    【解决方案1】:

    我不得不使用选项AllowCustomPaging 并定义我自己的页面,因为EntityCollection 不支持ICollection 类。

    我添加了以下代码来定义我的页面/项目

        pds.VirtualCount = Company.Locations.Count();
        pds.PageSize = 3;
        pds.AllowCustomPaging = true;
    

    以及我的页面生成方法中的一些其他代码

    for (int i = 0; i < (pds.VirtualCount/pds.PageSize);i++)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-29
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      相关资源
      最近更新 更多