将多个数据源合并到一个ASP.NET中继器中?
问题描述:
我有一个中继器,像这样:将多个数据源合并到一个ASP.NET中继器中?
<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>
我一个数据源绑定到中继器,像这样:
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 _
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()
问题是,我也想展示观众点的可用数量房间。但是,这需要以某种方式拉入current_occupancy/max_occupancy或执行计算(例如,max_occupancy - current_occupancy = actual_available),然后将其与房间一起返回。
最终的结果我要找的是一个按钮控件的文本看起来像这样返回每间客房: “室1 - 2打开”,“房8 - 等1打开”和
答
Amit_g的评论是关键。我需要将select语句放入actual_available = sh.max_occupancy - sh.current_occupancy。如果艾米特发布了答案,我会将“正确的”答案改为艾米特,以便给你答案的答案。 :)
答
谢谢davemackey :)像这样的东西。
选择新建随着{sh.room1,.actual_available = sh.max_occupancy - sh.current_occupancy}
您是否尝试过类似选择新建随着{sh.room1,.actual_available = sh.max_occupancy - sh.current_occupancy} – 2011-03-09 23:57:31
This Works!谢谢amit_g! – davemackey 2011-03-12 15:14:52