views:

22

answers:

1

The <li> tags generated by ASP.NET when I programatically add ListItems to my ListBox control do not have ID attributes. Is there any way that I can get them to have IDs so that I can get references to the elements from Javascript?

+2  A: 

Use the ListItem's attribute collection, like this...

ListItem item = new ListItem();
item.Attributes.Add("id", "myId");
myList.Items.Add(item);
kekekela
I tried this, and the tags in the html still have no ID attribute.
mcoolbeth
Please post your code, when I run that exact snippet this is what I get for the html option being generated from the list item:<option value="" id="myId"></option>
kekekela
Sorry. It worked fine. I had been looking in the wrong place.
mcoolbeth