populating radiobuttonlist from database programmatically

  • Thread starter Thread starter Hazzard
  • Start date Start date
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
 
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
 
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
 
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
******************************
 
Back
Top