style a Repeater item RRS feed

  • Question

  • User-125499312 posted


    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:


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

    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>");
    alPages.Add((i + 1).ToString())
    end if
    Next i
    Repeater1.DataSource = alPages;
    Repeater2.DataSource = alPages;

    Here is result of my demo:

    Best Regard,

    Yang Shen

    Monday, July 1, 2019 5:51 AM