Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RadioButtonList Bind

Status
Not open for further replies.

M444

Programmer
Feb 24, 2004
76
0
0
US
Hi,

I'm having problems binding a RadioButtonList...
I have values 1-10 stored as an integer in a field called score. I am using a DataList control to display records.

I want the respective RadioButton to be checked based on the score.

ie. if score = 3 the radiobutton with value 3 should be checked.

When I databind the RadioButtonList however I get this error:
"An invalid data source is being used for RBScore. A valid data source must implement either IListSource or IEnumerable."


<asp:radiobuttonlist id=RBScale runat="server" DataSource='<%# DataBinder.Eval(Container, "DataItem.Score") %>' RepeatDirection="Horizontal">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="1">3</asp:ListItem>

etc...
</asp:radiobuttonlist>


Any ideas?
 
Are you adding the values 1,2,3 by hand and then trying to also databind? If so, you will get an error. You either have to databind the list or set the values manually, not both.


JIm
 
I changed it just to databind, but I get the same error.
 
I think I am trying to use databinding in the wrong way? I want to have the appropriate radiobutton selected for each record in the datalist based on the value in the database for that record.

1 o 2 + 3 o 4 o 5 o Score = 2
1 o 2 o 3 + 4 o 5 o Score = 3
1 + 2 o 3 o 4 o 5 o Score = 1
1 o 2 + 3 o 4 o 5 o Score = 2
1 o 2 + 3 o 4 o 5 o Score = 2
1 o 2 o 3 o 4 o 5 + Score = 5
 
Can you show what the results would look like on the page acording to what you want? I think this will help me understand what you are trying to do and then I can help more.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top