I have a list defined like so:
- Item 1
-
I'm assuming that there is a valid reason for you not to use the BulletedList webserver control. Anyway, this is an interesting programming exercise that illustrates the internals of the Htmlservercontrol architecture and how they map to simple HTML tags.
The HTML ul
and li
tags are not directly mapped as HTMLServercontrols. This means that even if you add a runat="server"
attribute to the list, it's contents will not be directly accessible as listitems.
However, all controls not directly mapped as Html server controls are accessible via the HtmlGenericControl
class. This makes it possible to create and modify such controls dynamically.
The solution, therefore, is twofold:
runat="server"
so that you can access it in server-side code. Also, you should make the existing items in the list runat="server"
, else they will be only be accessible as an LiteralControl
that contains the first two listitems as plain text. The following (bare-bones simple) page demonstrates this procedure :
<%@ Page Language="VB" AutoEventWireup="false" %>
<%@ Import Namespace="System.Collections.Generic" %>
Test Page