Search code examples
c#asp.nettuplesasprepeater

Add multiple items to a asp repeater using tuples


I've created a repeater on the front end, and I need to add multiple items, the second item is a string and this needs to be added to the image src, any thoughts?

<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>

Below is the DataSource type

Tuple<string, string, double, double>

Solution

  • You need to use ImageUrl property and pass the value using the item binding syntax for ASP.NET WebForms <%# Item.Property #>

    <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>