Binding custom object to a listbox

Discussion in 'ASP .Net Datagrid Control' started by Fraggle, Nov 4, 2003.

  1. Fraggle

    Fraggle Guest

    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
     
    Fraggle, Nov 4, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blenderdude
    Replies:
    0
    Views:
    1,148
    blenderdude
    Aug 3, 2003
  2. COHENMARVIN
    Replies:
    1
    Views:
    585
    =?Utf-8?B?U3JlZWppdGggUmFtKE1DU0QuTkVUKQ==?=
    Oct 14, 2005
  3. =?Utf-8?B?SmF5YnVmZmV0?=
    Replies:
    9
    Views:
    865
    Phillip Williams
    Feb 21, 2006
  4. Bill Anderson

    Custom Component and Custom Textbox binding

    Bill Anderson, Dec 10, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    498
    Bill Anderson
    Dec 15, 2003
  5. JcFx
    Replies:
    0
    Views:
    313
Loading...

Share This Page