This is a migrated thread and some comments may be shown as answers.

LINQ GridView > sorting and paging

3 Answers 129 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
jon
Top achievements
Rank 1
jon asked on 28 May 2009, 01:46 PM
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!

3 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 30 May 2009, 11:00 AM
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.
0
jon
Top achievements
Rank 1
answered on 02 Jun 2009, 05:07 PM
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.
0
Accepted
PetarP
Telerik team
answered on 08 Jun 2009, 05:55 AM
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.
Tags
Getting Started
Asked by
jon
Top achievements
Rank 1
Answers by
PetarP
Telerik team
jon
Top achievements
Rank 1
Share this question
or