Home All Groups Group Topic Archive Search About

How Do I assign an ID to ListItem?

Author
19 Apr 2005 1:25 PM
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.

Author
19 Apr 2005 3:36 PM
Teemu Keiski
Replied in already in buildingcontrols

===========================
ListItem doesn't have an ID, it's not deriving from control so it cannot
have ID. Instead, you'd need to search the ListItem from ListItemCollection
(Items property) with the value that was posted.

Dim litem As ListItem=
lst.Items.FindByValue(Request.Form("returnsvaluetolookfor")).

where lst is the control having the ListItem to look for.

==========================

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

Show quoteHide quote
"Amelyan" <bamel***@wi.rr.com> wrote in message
news:%23WkOUNORFHA.688@TK2MSFTNGP10.phx.gbl...
> 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.
>
Author
20 Apr 2005 9:18 PM
Amelyan
I need to identify ListItem of dynamically generated CheckBoxList with
Request.Form.  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

Show quoteHide quote
"Teemu Keiski" <jot***@aspalliance.com> wrote in message
news:uvHc9VPRFHA.1500@TK2MSFTNGP09.phx.gbl...
> Replied in already in buildingcontrols
>
> ===========================
> ListItem doesn't have an ID, it's not deriving from control so it cannot
> have ID. Instead, you'd need to search the ListItem from
> ListItemCollection
> (Items property) with the value that was posted.
>
> Dim litem As ListItem=
> lst.Items.FindByValue(Request.Form("returnsvaluetolookfor")).
>
> where lst is the control having the ListItem to look for.
>
> ==========================
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
>
> "Amelyan" <bamel***@wi.rr.com> wrote in message
> news:%23WkOUNORFHA.688@TK2MSFTNGP10.phx.gbl...
>> 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.
>>
>
>
Author
9 Jun 2005 5:32 AM
Mark
Hi Amelyan,

Not sure why you want to use Request.Form. Can you not use code-behind? I
presume you are using code-behind to dynamically populate the checkboxlist?
You could use code-behind to do something like this:

dim myitem as listitem
for each myitem in chkboxlist.items
   if myitem.selected then
      dim myvar as int32 = ctype(myitem.value, int32)
   end if
next

Obviously, the above would be a problem for more than one selection, but
gives an idea. If this doesn't help, would need more info as to what you are
doing (eg, how are you populating the checkboxlist?)

Regards,
Mark St Denis

Show quoteHide quote
"Amelyan" wrote:

>
> I need to identify ListItem of dynamically generated CheckBoxList with
> Request.Form.  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