Combine Multiple Data Sources to a Single ASP.NET Repeater?
I have a repeater like so:
<asp:Repeater ID="rptrRooms" runat="server" OnItemCommand="Choose_Room">
<ItemTemplate>
<asp:Button ID="btnChooseRoom" runat="server"
CommandName="<%# Container.DataItem.ToString %>" Text="<%# Container.DataItem %>"
/>
</ItemTemplate>
</asp:Repeater>
I bind a data source to the repeater like so:
Dim dbRooms As New pbu_housingEntities
Dim gender As String = Session("gender").ToString
Dim hall As String = CStr(Session("hall"))
Dim selectedRooms = (From sh In dbRooms.Rooms 开发者_C百科_
Where sh.gender = gender _
Where sh.current_occupancy < sh.max_occupancy _
Where sh.is_available = True _
Where sh.building_name = hall _
Select sh.room1
)
rptrRooms.DataSource = selectedRooms
rptrRooms.DataBind()
Problem is, I also want to show the viewer the available number of spots in the room. But this requires somehow pull in either the current_occupancy / max_occupancy or in performing a calculation (e.g. max_occupancy - current_occupancy = actual_available) and then returning that with the room.
The end result I'm looking for is to return each room in a button control with text that looks like this: "Room 1 - 2 Open" "Room 8 - 1 Open" and so on
Thanks davemackey :) Something like this.
Select New With {sh.room1, .actual_available = sh.max_occupancy - sh.current_occupancy}
Amit_g's comment above was the key. I needed to put into the select statement actual_available = sh.max_occupancy - sh.current_occupancy. If Amit posts an answer, I'll change the "correct" answer over to Amit to give you the credit for the answer. :)
精彩评论