setting the selected value of radiobutton list from database value

J

jwright1

I am trying to set the selected value of a radio button list from a
value stored in a table of a database. using vb codebehind asp.net. I
tried binding the selected index item and selected index value to the
dataset field for the selected line item. This is on a details page.
When I do this I get an Index 0 value error.

My goal it to have the radiobutton selected yes if the database value
is yes ect.

Thanks for the help.
 
K

K B

Since you show no code, let's assume you populate your radionbutton list
(rblTest) as such:

Value Text
1 Yes
2 No

or whatever values you're using.

Also assuming you store the Value in your database and not the text, you
retrieve your value, for example, as
Dim iValue as Integer = ds.Tables(0).Rows(0)("ButtonValue")

To select the correct radio button you would do:

rblTest.SelectedValue = iValue (either 1 or 2)

If you're storing Yes/No as text in the value field, then use
rblText.SelectedItem.Text = sValue (Yes or No).

The index item is not involved here...only Value or Text.

HTH,
Kit
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top