0

I have this custom paging, and I'm trying to add attribute to the ListItem.
I'd like to use this attribute (or class) to style the item with css later on.

aspx code:

<asp:Repeater ID="rptPager" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="lnkPage" runat="server" Text = '<%#Eval("Text") %>' CommandArgument = '<%# Eval("Value") %>' Enabled = '<%# Eval("Enabled") %>' OnClick = "Page_Changed"></asp:LinkButton>
    </ItemTemplate>
</asp:Repeater>

Here's the relevant code behind:

if (currentPage > 5) {
ListItem li = new ListItem("...", "", false);
li.Attributes.Add("extra", "true");
pages.Add(li);
}

Here's the html generated for that item:

<a id="MainContent_rptPager_lnkPage_2" class="aspNetDisabled">...</a>

Just to clarify:
I'm also adding more items before and after this.
Also the item might not get generated if there aren't enough pages.
I end up with something like this:
First 2 3 4 ... >> Last
or: First << ... 3 4 5 6 7 8 9 >> Last

  • what is the expected HTML ? – hasnayn Oct 26 '17 at 13:40
  • This seems related to https://stackoverflow.com/questions/20065538/listitem-additional-custom-values In the working example (which this may be duplicate of) the list item is added to a drop down's items collection, and not directly to the page. – Greg Oct 26 '17 at 13:46
  • @hasnayn The attribute should be added. –  Oct 26 '17 at 14:04
  • @Greg I don't see how that can help me. –  Oct 26 '17 at 14:04
  • If this is inside a repeater you can use rptData_ItemDataBound https://www.developer.com/net/asp/article.php/3609851/ASPNET-Tip-Use-the-ItemDataBound-Event-of-a-Repeater.htm – boateng Oct 26 '17 at 14:44
  • @numbtongue Yes, it is in a repeater. I've updated the question to show it. How would I call this event (or a custom one) only when I need it? I would need to add the attributes to only 1 or 2 elements if they are generated. –  Oct 26 '17 at 15:25
  • check out bootstrap pagination.. if you look at the bottom of the page in my example, you can also check for pagination of your current page by checking what link was clicked, sorry can help more https://forums.asp.net/t/1915217.aspx – boateng Oct 26 '17 at 15:51

0 Answers0