1

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

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

3 Comments

Thanks, but still not working. Will it help if I say that Model ws built with DB first?
You could try and do return arrivals.ToList(), but I don't think that is the answer. Have you tried setting AllowPaging="false", just to see if it works or if you get another exception?
Yes, ToList is not answer. I did tried to change to be AllowPaging="false", but there is another error saying about my SelectMethod not return IQueryable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.