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 ID
s so that I can get references to the elements from Javascript?
views:
22answers:
1
+2
A:
Use the ListItem's attribute collection, like this...
ListItem item = new ListItem();
item.Attributes.Add("id", "myId");
myList.Items.Add(item);
kekekela
2010-07-06 19:09:05
I tried this, and the tags in the html still have no ID attribute.
mcoolbeth
2010-07-06 19:40:28
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
2010-07-06 19:51:18
Sorry. It worked fine. I had been looking in the wrong place.
mcoolbeth
2010-07-06 20:02:45