Link to home
Create AccountLog in
Avatar of smagnus1

asked on

Dynamically Load Radio Button List

Hi all,

I am attempted to load a radio button list dynamically on page load based on the results in a database table, and have succeeded in doing so; partially.  What I am after is, my database table has 2 fields - ItemText and ItemValue.  I know that if I manually enter the ItemText and ItemValue in the buttonlist, these 2 fields are available - see "Items" property and Collection.  The code snippet below work, but I only get to load Item Text, not item value.  My reasoning in doing so is that the users don't understand the values, so I am giving them an understandable text to make it more user friendly, but I need the value for my insert into another table at a later time.  Needless to say, I am not a fan of hardcoding anything as items change from time to time, and I would rather fix this while I can at this time as opposed to putting it off to later.  Thanks and take care.

For Each tRow In tTbl.Rows
        RadioButtonList1.Items.Add(tRow "ItemText").ToString)

Open in new window

Avatar of Jeeva Subburaj
Jeeva Subburaj
Flag of United States of America image

how about this
r Each tRow In tTbl.Rows
        RadioButtonList1.Items.Add(new ListItem("ItemText","ItemValue)).ToString)
Avatar of sanjeewaj
Flag of Sri Lanka image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of smagnus1


Thanks!  Worked like a champ!