如何使用VB.NET DataBind多个项目?

如何使用VB.NET DataBind多个项目?

问题描述:

我运行下面的查询:如何使用VB.NET DataBind多个项目?

' Show which halls they are eligible for. 
     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, actual_available = sh.max_occupancy - sh.current_occupancy 
          ) 
     rptrRooms.DataSource = selectedRooms 
     rptrRooms.DataBind() 

其中,你可以看到,被绑定到一个中继器。现在,它包含多个值,我想在一个很好的格式化的方式来显示它们,下面伪代码:

<asp:Repeater ID="rptrRooms" runat="server" OnItemCommand="Choose_Room"> 
    <ItemTemplate> 
     <asp:Button ID="btnChooseRoom" runat="server" 
     CommandName="<%# Container.DataItem.Room1.ToString %>" Text="<%# Container.DataItem.Room1 %> : Available : <%# Container.DataItem.actual_available %>" 
     /> 
    </ItemTemplate> 
</asp:Repeater> 

试试这个:

Text='<%# String.Format("{0} : Available : {1}", Container.DataItem.Room1, Container.DataItem.actual_available) %>' 
+0

我给一个尝试,但它不” t喜欢双重“”,所以我改变了内部的''。它运行但返回了以下错误: BC30201:预期的表达式。 来源错误: 第6行 第7行: 第8行:”Text =““ 第10行: – davemackey 2011-03-12 15:44:36

+0

好的,这真的很愚蠢 - 我只需要将引号反转 - 现在外层是”内层“,它工作得很好。谢谢你的帮助! – davemackey 2011-03-12 15:46:28