LINQ GridView > sorting and paging

4 posts, 1 answers
  1. jon
    jon avatar
    33 posts
    Member since:
    Dec 2008

    Posted 28 May 2009 Link to this post

    I am having a lot of trouble with simply paging my GridView when using LINQ.  This is my GridView:

    <asp:GridView ID="gridViewAnimals" runat="server"
                        AutoGenerateColumns="false" AllowPaging="false" AllowSorting="true" PageSize="5" Width="90%"
              CellPadding="2" BorderColor="White" BorderWidth="0" BorderStyle="None">
              <Columns>
                <asp:HyperLinkField HeaderText="Edit" DataNavigateUrlFields="IdAnimal" DataNavigateUrlFormatString="ManageAnimal.aspx?IdAnimal={0}" Text="Edit" />
                <asp:BoundField DataField="AnimalId" HeaderText="Animal Id" SortExpression="AnimalId" />
                <asp:BoundField DataField="StrainId" HeaderText="Strain Id" SortExpression="StrainId" />
                <asp:CommandField ShowDeleteButton="True" HeaderText="Delete" DeleteImageUrl="~/Images/icon-delete.gif" ButtonType="Image" />
              </Columns>
    </asp:GridView>

    This is my LINQ statement:
    result = from a in scope.Extent<Animal>()
            select new
            {
               a.IdAnimal,
               a.AnimalId,
               StrainId = a.Strain.StrainId,
               Location = a.Cage.Location.Building + a.Cage.Location.Room
            };
    gridViewAnimals.DataSource = result;
    gridViewAnimals.DataBind();

    Do you have a solution for when I want to sort on the AnimalId and StrainId columns?  Help us much appreciated.  I tried to implement several solutions, but I am thinking that the complexity of OpenAccess might be what is preventing it from working.  Thanks!
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 30 May 2009 Link to this post

    Hello jon,
    first of all you will need to to set the the AllowPaging property of the grid to true.
    AllowPaging="false" 
    Than you will have to implement the Page Changing event of the grid and there you will have to properly handle the changing of the page. I advice you to use our RadGrid because it is able to handle those events for you without the need of you writing any additional code.

    Sincerely yours,
    PetarP
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. jon
    jon avatar
    33 posts
    Member since:
    Dec 2008

    Posted 02 Jun 2009 Link to this post

    Your Radgrid seems to work fairly well.  If you have an example of how to sort and page using the .Net gridview, we would definitely still like to see that.
  5. Answer
    PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 08 Jun 2009 Link to this post

    Hello jon,
    unfortunatly we do not have such examples online at the moment. What I can offer you is to open a support ticket and our team will cook up something for you and send it to you.

    Best wishes,
    Petar
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
Back to Top