views:

362

answers:

1

I am working on a traditional WebForms project. In the project I am trying out some Linq datasources with plans to eventually migrate to an MVC architecture. I am still very new to Linq.

I have a GridView using a Linq datasource. The entities I am showing has a to many relationship and I would like to get the maximum value of a column in the many side of the relationship.

I can show properties of the base entity in the gridview:

<asp:TemplateField HeaderText="Number" SortExpression="tJobBase.tJob.JobNumber">
  <ItemTemplate>
     <asp:Label ID="Label1" runat="server" Text='<%# Bind("tJobBase.tJob.JobNumber") %>'>
     </asp:Label>
  </ItemTemplate>
</asp:TemplateField>

I can also show the count of the many related property:

<asp:TemplateField HeaderText="Number" SortExpression="tJobBase.tJob.tHourlies.Count">
  <ItemTemplate>
     <asp:Label ID="Label1" runat="server" Text='<%# Bind("tJobBase.tJob.tHourlies.Count") %>'>
     </asp:Label>
  </ItemTemplate>
</asp:TemplateField>

Is there a way to get the max value of a column called WeekEnding in the tHourlies collection to show in the GridView?

A: 

Try:

Bind("tJobBase.tJob.tHourlies.Max(w => WeekEnding)")

but I think it would be better to make an specific query wich returns in a field the max value you want, and bind this query to your gridview. Then you could access this field as usual with something like

Bind("MaxWeekEnding")
eKek0
I tried using this before and I get the error that "A call to Bind was not well formatted." I experimented with calls such as this in code and it works fine. Is this just not available in Bind calls?
Stephen Pellicer
Did you try Eval instead of Bind?
eKek0