populating radiobuttonlist from database programmatically

H

Hazzard

I store radiobuttonlist values in the db using the string value of the radio
button item value. (nvarchar)

I am creating an edit functionality on the asp.net form so that when I reuse
my dataentry form for edit, I search the database for the row containing the
data I want, and then populate all the form fields.

here is what I have so far. What I don't know what to do is for cases where
a dirty database has no associated value for the radiobuttonlist, I don't
want to select anything. How do I do that?
***************
dbaseReturnValue = arParms(17).Value.ToString() 'get value from returned
stored procedure call.
For Each li In RadioButtonList.Items
i += 1
If (RadioButtonList.Value = dbaseReturnValue Then //but Value is
not a valid member. what do i use?
RadioButtonList.SelectedValue = dbaseReturnValue
li.Selected = True
else
RadioButtonList.SelectedValue = ???????????
End If
Next
***************
Thank you,
Greg Hazzard
 
H

Hazzard

Thank you Justin ! Of course, it sets it to a value out of the range of the
valid values.
And what about the comparison of the database value, eg. "radiobuttonvalue1"
?
Which property do I use to iterate through the list of radiobutton item
values to compare with say, "radiobuttonvalue1?" Is it
radionbuttonlist.items.??? or
radiobutton.items.searchbyvalue("radiobuttonvalue1")..

thank you,
Greg
 
S

S. Justin Gengo

Greg,

'---This code seems like more work but I've found it to be the fastest way
to iterate

' through a loop because it calls on less objects

Dim ItemCount, ItemLoop As Int32

ItemCount = RadioButtonList.Items.Count - 1

For ItemLoop = 0 To ItemCount

If RadioButtonList.Items(ItemLoop).Value = dbaseReturnValue Then

RadioButtonList.SelectedIndex = ItemLoop

Exit For

End If

Next



Justin
 
H

Hazzard

Thank you Justin! It even floats over a dirty database. Clean algorithm.
_greg
************************************
arReturnParms(x) = arParms(x).Value.ToString() 'value returned from
database stored procedure.
RadioButtonList.SelectedIndex = -1 'no radio buttons
checked
ItemCount = RadioButtonList.Items.Count - 1
For ItemLoop = 0 To ItemCount
If RadioButtonList.Items(ItemLoop).Value = arReturnParms(x) Then
'unless there is a match
RadioButtonList.SelectedIndex = ItemLoop
Exit For
End If
Next
******************************
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top