views:

53

answers:

2

Hello..

I have a class called "Answer" includes:

int ID;

String Text;

And I have a list of them like this:

List<Answer> myList;

in the web page, I have RadioButtonList that I want to bind data from the list above, so I've done:

AnswersButtonList.DataSource = myList;
AnswersButtonList.DataTextField = "Text";
AnswersButtonList.DataValueField = "ID";
AnswersButtonList.DataBind();

but the DataValueField didn't bind well! I feel I'm doing that in a wrong way, waiting your help :)

A: 

perhaps try changing your ID property to string.

according to documentation here DataValueField is a string property:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.datavaluefield.aspx

Sonic Soul
Thanks dear, but sorry it didn't work!I've changed the ID property from int to string, but nothing happened well!
Hashem Alrifai
and you verified that the ID property on your collection gets populated ?
Sonic Soul
and you're checking the page source to see if values were not populated?
Sonic Soul
A: 

This works for me

Answer class has following properties

public string AnswerID
{
    get { return theAnswerID; }
    set { theAnswerID = value; }
}

public string Text
{
    get { return theText; }
    set { theText = value; }
}

then create your list and bind. If it still isn't working then I'd bind to a gridview to see what is getting churned out by your list.

Colin D