Search code examples
c#gridviewmodelasp.net-4.5selectmethod

ASP.NET 4.5 data binding model SelectMethod throw error


I confused with this new pattern. Everything is looking simple when you are reading tutorial. But the simplest task I cannot complete - bind data model to GridView. Here is GridView code:

 <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">

And SelectMethod here:

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;
        }

This look simple and smooth, but I got error: When the DataBoundControl has paging enabled, either the SelectMethod should return an IQueryable or should have all these mandatory parameters : int startRowIndex, int maximumRows, out int totalRowCount


Solution

  • Stupid mistake. I just mention wrong table name in ItemType.