Skip to main content
 首页 » 编程设计

c#之使用元组将多个项目添加到 asp 转发器

2024年02月05日9mayingbao

我在前端创建了一个中继器,我需要添加多个项目,第二个项目是一个字符串,这需要添加到图像 src,有什么想法吗?

<asp:Repeater runat="server" ID="WeatherForcastWeek" > 
  <ItemTemplate> 
     <td> 
       <asp:Label runat="server" ID="Day1" /> 
       <asp:Image runat="server" ID="WeatherIcon" /> 
       <asp:Label runat="server" ID="Min" /> 
       <asp:Label runat="server" ID="Max" /> 
     </td> 
  </ItemTemplate> 
</asp:Repeater> 

下面是DataSource类型

Tuple<string, string, double, double> 

请您参考如下方法:

您需要使用 ImageUrl 属性并使用 ASP.NET WebForms <%# Item.Property #> 的项绑定(bind)语法传递值

<asp:Repeater runat="server" ID="WeatherForcastWeek" ItemType="System.Tuple`4    [System.String,System.String,System.Double,System.Double]"> 
  <ItemTemplate> 
     <td> 
       <asp:Label runat="server" ID="Day1" Text="<%# Item.Item1 %>" /> 
       <asp:Image runat="server" ID="WeatherIcon" ImageUrl="<%# Item.Item2 %>" /> 
       <asp:Label runat="server" ID="Min" Text="<%# Item.Item3 %>"/> 
       <asp:Label runat="server" ID="Max" Text="<%# Item.Item4 %>"/> 
     </td> 
  </ItemTemplate> 
</asp:Repeater>