locked
style a Repeater item RRS feed

  • Question

  • User-125499312 posted

    hi

    i am adding items to a Repeater :

    Dim alPages As New ArrayList()

    For i = intPageCountStart To intPageCountEnd ' pgItems.PageCount - 1 'For i As Integer = 0
          alPages.Add((i + 1).ToString())

    Next i

    this working fine, however, i would like to add a style to a particular item

    If i = PageNumber Then

      alPages.Add((i + 1).ToString()) - add with a style

    end if

    thx for ur help

    Friday, June 28, 2019 8:14 PM

All replies

  • User-719153870 posted

    Hi yzidell,

    Whether you bind alPages directly to repeater or to controls(like Labels ) within the repeater, you can add styles to a specific item in alPages by adding <span> tags.

    Please refer to below codes:

    ASPX:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Repeater ID="Repeater1" runat="server">
                    <ItemTemplate>
                        <%#Container.DataItem%>
                    </ItemTemplate>
                </asp:Repeater><br />
                <asp:Repeater ID="Repeater2" runat="server">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%#Container.DataItem%>'></asp:Label>
                    </ItemTemplate>
                </asp:Repeater>
            </div>
        </form>
    </body>
    </html>

    Background code:

    Dim alPages As New ArrayList()
    Dim intPageCountStart As Integer = 0
    Dim intPageCountEnd As Integer = 10
    Dim PageNumber As Integer = 5
    For i = intPageCountStart To intPageCountEnd 
    If i = PageNumber Then
    alPages.Add("<span style='color:red;font-size:20px;'>" + (i + 1).ToString()+"</span>");
    else
    alPages.Add((i + 1).ToString())
    end if
    Next i
    Repeater1.DataSource = alPages;
    Repeater1.DataBind();
    Repeater2.DataSource = alPages;
    Repeater2.DataBind();
    

    Here is result of my demo:

    Best Regard,

    Yang Shen

    Monday, July 1, 2019 5:51 AM