radioList

G

Guest

I have a radioList on my web form that has to be checked based on a data item
from my database, how can I check one of the radio buttons in the list?

example: my data is returned 1, 2, 3
and in my list I need to one of them checked based on the number returned?
how can i do that in .net?
 
G

Guest

Well, I am more Vb .net but my guess would be.... when you know the value you
returned from the database... I then say... rbList.selectedValue = your
database value.
 
G

Guest

I tried that and it didn't work, i also did

case (modelNumber)
{
case "0":
radio.selectedItem.selected = true;
break;
case "525":
radio.selectedItem.selected = true;
}

and I get

Object reference not set to an instance of an object and it goes to this line:
radio.selectedItem.selected = true;
 
E

Elliot Rodriguez

It sounds like it may be an event order problem and the control has not yet
been rendered when you try to set the property.

Have you tried casting a control in the ItemDataBound or ItemCreated event,
then setting its property?
 
A

Alec MacLean

Assuming modelNumber is an Integer datatype (or cast to one):

'RadioButtonList has a zero-based index for items
me.myRadioList.SelectedIndex = cint(modelNumber)

Hope that helps.

Al
 

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,776
Messages
2,569,603
Members
45,190
Latest member
Martindap

Latest Threads

Top