How to add class to a listitem from code behind


  1. if (pageCount > 0)
  2.     {
  3.         pages.Add(new ListItem("First", "1", currentPage > 1));
  4.         for (int i = 1; i <= pageCount; i++)
  5.         {
  6.             pages.Add(new ListItem(i.ToString(), i.ToString(), i != currentPage));
  7.         }
  8.         pages.Add(new ListItem("Last", recordCount.ToString(), currentPage < pageCount));
  9.     }
  10.        
  11. <ul class="pages-pagina">
  12. <li class="pages previous"><a href="#">Previous</a></li>
  13. <li class="pages selected"><a href="#">1</a></li>
  14. <li class="pages"><a href="#">2</a></li>
  15. <li class="pages"><a href="#">3</a></li>
  16. <li class="pages"><a href="#">4</a></li>
  17. <li class="pages"><a href="#">5</a></li>
  18. <li>...</li>
  19. <li class="pages last"><a href="#">10</a></li>
  20. <li class="pages next"><a href="#">Next</a></li>
  21.  
  22.  
  23. </ul>
  24.        
  25. ListItem li = new ListItem(i.ToString(), i.ToString(), i != currentPage);
  26. li.Attributes.Add("class", "pages");


Learn More :