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

标签 c# asp.net tuples asprepeater

我在前端创建了一个中继器,我需要添加多个项目,第二个项目是一个字符串,这需要添加到图像 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>

关于c# - 使用元组将多个项目添加到 asp 转发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36478156/

相关文章:

c# - TextBlock 中的绑定(bind)在 WPF 中不起作用

C# - 使用 Directory.EnumerateDirectories 深度优先?

asp.net - 如何在复选框的 CheckedChanged 事件中获取中继器项目?

asp.net - 带有 Visual Studio 2017 和 IIS Express 的 ngrok 无法连接

Python:用反斜杠连接元组

swift - swift 中不同大小和类型的元组列表

c# - 在 C# 中调用标量函数

javascript - 没有 PreviousPage 的 ASP.NET 跨页发布

Python:遍历并按元素比较 2 个元组列表

c# - 为 OwnesOne 导航属性创建索引