Search code examples
asp.netrepeater

ListView inside Repeater Asp.Net


I have a class like

class BroadCast
{
    public string Comment{ get; set; }
    public DateTime Date{ get; set; }
    public List<string> DisplayUsers { get; set; }
}

I am binding List<BraodCast> to Repeater. Till now I had only two columns in Repeater but I need to add one more now to display list of DisplayUsers. I am thinking to use ListView inside repeater so I bound it like below

<asp:ListView ID="lstDisplayRole" runat="server" DataSource='<%# Eval("DisplayUsers") %>'  >
   <ItemTemplate>
             <asp:Label ID="lblRoleName" runat="server" ForeColor="Black" Text='<%#Eval(index)%>' />
   </ItemTemplate>
</asp:ListView>

index is nothing, I am finding what could be there to make my listview work. I mean if it was a DataTable instead of List<string> than it would have been very easy to use Eval("ColumnName") but this is not a case here, I don't have columns, it's just a list of string. How can I achieve this?


Solution

  • To get the current bound item itself (a string in this case), use Container.DataItem. There's nothing to evaluate, so Eval() isn't needed.

    <asp:Label ID="lblRoleName" runat="server" ForeColor="Black" Text='<%# Container.DataItem %>' />