无法计算未实现 ICollection 的数据源的计数。

问题描述 投票:0回答:1

这是我的代码

 var q = from a in bh
                join b in hr on a.HotelCode equals b.hotelCode
                select new
        {
            a.HotelCode,
            a.ImageURL_Text,
            a.HotelName,
            a.StarRating,    
            a.HotelAddress,
            a.Destination,
            a.Country,
            a.HotelInfo,
            a.Latitude,
            a.Longitude,
            b.totalPrice,
            b.totalPriceSpecified,
            b.totalSalePrice,
            b.totalSalePriceSpecified,
            b.rooms

    };

        //rptHotels.DataSource = getres.availableHotels;

        PagedDataSource objPds = new PagedDataSource();
        objPds.DataSource = q;
        objPds.AllowPaging = true;
        objPds.PageSize = 10;// Convert.ToInt32(ddlPageNo.SelectedValue);

        objPds.CurrentPageIndex = CurrentPage;

        lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of "
           + objPds.PageCount.ToString();

        // Disable Prev or Next buttons if necessary
        cmdPrev.Enabled = !objPds.IsFirstPage;
        cmdNext.Enabled = !objPds.IsLastPage;

        rptHotels.DataSource = objPds;
        rptHotels.DataBind();

错误有自我解释,但没有找到解决此错误的方法......

c# pagination repeater
1个回答
4
投票

使用ToArray():

objPds.DataSource = q.ToArray();
© www.soinside.com 2019 - 2024. All rights reserved.