Thursday, March 22, 2012

setting the selected value of radiobutton list from database value

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.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

*** Sent via Developersdex http://www.developersdex.com ***

0 comments:

Post a Comment