radioList

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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.
 
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;
 
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?
 
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
 
I got it to bind correctly, but now if the user changes it on the page its
still reading the default value.

example:

if the pages loads and radiobutton #2 is selected and I make a change and
select radiobutton #3, it still reads it as checkbox #2 is selected, so how
can i get the value of the correct radiobutton that is selected
 

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

Back
Top