Stupid mistake. I just mention wrong table name in ItemType.
ASP.NET 4.5 data binding model SelectMethod throw error
-
11-10-2022 - |
Pregunta
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
Solución
Otros consejos
This works for me:
<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>
Code:
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; }
}
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow