Binding custom object to a listbox

F

Fraggle

I have a class I wish to enter into a listbox

public Class AnswerListItem

Public Answer As String
Public Order As integer

End Class

Here is where I create the classes I wish to have in my box

dim AnswersDS as dataset
AnswersDS = QuestionDB.GetAnswersbyQuestion(dr("QuestionNo"))

dim drw as datarow

for each drw in answersDS.tables(0).rows

dim a as new answerlistitem()

a.Answer = "ans"
a.order = 3
answeritems.add(a)

next

AnswersList.datatextfield="Answer"
AnswersList.databind()

I get the error message " Exception Details: System.Web.HttpException:
DataBinder.Eval: 'ASPNetPortal.AnswerListItem' does not contain a
property with the name answer."

at Line 138:AnswersList.databind()

I tried changing to

AnswersList.datatextfield=DataBinder.Eval(container.DataItem,
"answer")

However, I get the error " Compiler Error Message: BC30451: Name
'container' is not declared."

If I comment out the AnswersList.datatextfield= line then I get the
right number of "ASPNetPortal.AnswerListItem"s in my listbox. So I
feel I am close!

Any help gratefully received!

If you need more code then ask!
Thanks

Fragg
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top