ASP.NET Repeater bind List<string> ASP.NET Repeater bind List<string> asp.net asp.net

ASP.NET Repeater bind List<string>


Just use <%# Container.DataItem.ToString() %>

If you are worried about null values you may want to refactor to this (.NET 6+)

<asp:Repeater ID="repeater" runat="server">    <ItemTemplate>        <%# Container.DataItem?.ToString() ?? string.Empty%>    </ItemTemplate></asp:Repeater>

Note if you are using less than .NET 6 you cannot use the null-conditional operator Container.DataItem?.ToString()


Set the ItemType to System.String

<asp:Repeater ItemType="System.String" runat="server">    <ItemTemplate>        <%# Item %>    </ItemTemplate></asp:Repeater>


rptSample.DataSource = from c in lstSample select new { NAME = c };

in the repeater you put

<%# Eval("NAME") %>