【问题标题】:Combine Multiple Data Sources to a Single ASP.NET Repeater?将多个数据源组合到一个 ASP.NET 中继器?
【发布时间】:2011-03-09 20:28:56
【问题描述】:

我有一个这样的中继器:

<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 开放”等等

【问题讨论】:

  • 您是否尝试过类似 Select New With {sh.room1, .actual_available = sh.max_occupancy - sh.current_occupancy}

标签: asp.net entity-framework data-binding repeater


【解决方案1】:

谢谢 davemackey :) 像这样的。

选择新的 {sh.room1, .actual_available = sh.max_occupancy - sh.current_occupancy}

【讨论】:

    【解决方案2】:

    Amit_g 上面的评论是关键。我需要将实际可用 = sh.max_occupancy - sh.current_occupancy 放入选择语句中。如果 Amit 发布了答案,我会将“正确”答案更改为 Amit,以便为您提供答案。 :)

    【讨论】:

      猜你喜欢
      • 2019-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      • 2023-03-08
      • 2011-07-09
      • 1970-01-01
      • 2020-02-02
      • 2022-09-27
      相关资源
      最近更新 更多