How do I assign an ID to ListItem?


A

Amelyan

How can I assign an ID to dynamically generation ListItem that I add to
dynamically generated CheckBoxList or RadioButtonList? I need to identify
the specific ListItem later through Request.Form when user sends back data.
 
Ad

Advertisements

G

Guest

Hi,

There is no ID on the ListItem object. It renders as an <OPTION> element of
the <SELECT> html object, and this does not have an ID. If you need to access
a listitem I would advise to use the value property. There is usually no
reason that two values be the same in the same list.

hope this helps,
John
 
Ad

Advertisements

A

Amelyan

Hi John,

Your suggestion works for RadioButtonList. However, for CheckBoxList, I
originally tried to set CheckBoxList.ListItem.Value to something, but the
value never gets rendered into html. Instead, the Value gets set to "on",
if user checked the CheckBoxList.ListItem. You can try it by dynamically
creating CheckBoxList. There is no way to identify which
CheckBoxList.ListItem was selected through Request.Form. This is why I
decided that maybe there is a way to set ID, or any other way to identify
ListItem by other then ListItem.Text.

Thanks,
Amelyan
 

Top