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.
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top