Bind (Populate) Unordered List (UL) in ASP.Net Repeater with Eval function using C# and VB.Net

Last Reply 8 days ago By dharmendr

Posted 8 days ago

Dear All,

I have one unordered list and list items and i want to bind in the repeater control for options a, b, c, d, e.

I want to bind the UL in the Repeater using Eval.

This is the ordered list.

<ul>
<li>11</li>
<li>22</li>
<li>33</li>
<li>44</li>
<li>55</li>
</ul>

Reapeater: 

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:Label ID="lbl_number" runat="server" CssClass="fa fa-question" Text='<%# Eval("QuestionNo") %>'></asp:Label>
        <asp:Label ID="Label1" runat="server" Text=". "></asp:Label>
        <asp:Label ID="lbl_question" runat="server" Text='<%# Eval("QuestionText") %>' ></asp:Label>
    </ItemTemplate>
</asp:Repeater>

Thanks.

Posted 8 days ago

Hi v,

Refer below code.

HTML

<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <ul>
    </HeaderTemplate>
    <ItemTemplate>
        <li>
            <%# Eval("Id")%>
        </li>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn("Id") });
        dt.Rows.Add(11);
        dt.Rows.Add(12);
        dt.Rows.Add(13);
        dt.Rows.Add(14);
        dt.Rows.Add(15);
        Repeater1.DataSource = dt;
        Repeater1.DataBind();
    }
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim dt As Data.DataTable = New Data.DataTable()
        dt.Columns.AddRange(New Data.DataColumn() {New Data.DataColumn("Id")})
        dt.Rows.Add(11)
        dt.Rows.Add(12)
        dt.Rows.Add(13)
        dt.Rows.Add(14)
        dt.Rows.Add(15)
        Repeater1.DataSource = dt
        Repeater1.DataBind()
    End If
End Sub

Screenshot