This question is locked. New answers and comments are not allowed.
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!
<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!