1

我对这种新模式感到困惑。当您阅读教程时,一切看起来都很简单。但最简单的任务我无法完成 - 将数据模型绑定到 GridView。这是 GridView 代码:

 <asp:GridView ID="gvIlves" runat="server" AllowPaging="True" AllowSorting="True" ItemType="GuideOnline_1_.Models.xTourist"
                AutoGenerateColumns="False" DataKeyNames="Kod" CssClass="table table-striped tablesorter"
                ClientIDMode="Static" PageSize="50" SelectMethod="SelectArrival" UpdateMethod="UpdateArrival">

和 SelectMethod 在这里:

public IQueryable<GuideOnline_1_.Models.xTourist> SelectArrival()
        {
            var now = DateTime.Today.AddDays(-3);
            IQueryable<GuideOnline_1_.Models.xTourist> arrivals = _db.xTourist;
            arrivals = arrivals.Where(p => p.Ответственный !=null).Where(p => p.Номер == null).Where(p => p.Датапр >= now);
            return arrivals;
        }

这看起来简单流畅,但我得到了错误: 当 DataBoundControl 启用分页时,SelectMethod 应该返回一个 IQueryable 或者应该具有所有这些强制参数:int startRowIndex、int maximumRows、out int totalRowCount

4

2 回答 2

2

愚蠢的错误。我只是在 ItemType 中提到了错误的表名。

于 2014-02-18T11:16:30.033 回答
1

这对我有用:

 <asp:GridView ID="gvIlves" runat="server" AllowPaging="True" AllowSorting="True" ItemType="WebApplication1.Tourist"
            AutoGenerateColumns="True" DataKeyNames="Kod" CssClass="table table-striped tablesorter"
            ClientIDMode="Static" PageSize="50" SelectMethod="SelectArrival"></asp:GridView>

代码:

namespace WebApplication1
{
public partial class _Default : Page
{
    public IQueryable<Tourist> SelectArrival()
    {
        return new EnumerableQuery<Tourist>(new List<Tourist>
        {
            new Tourist{ Kod = "1", Name = "Joe", Age = "35"},
            new Tourist{ Kod = "2", Name = "Cliff", Age = "45"},
            new Tourist{ Kod = "3", Name = "Dan", Age = "32"},
        });
    }
}

public class Tourist
{
    public string Kod { get; set; }
    public string Name { get; set; }
    public string Age { get; set; }
}
}
于 2014-02-14T12:59:40.220 回答