S
Shrage Smilowitz
I try to create a custom collection which i will then use to databind and
its not working.
Class Book
Public BookName As String
Sub New(ByVal lBookName As String)
Me.BookName = BookName
End Sub
End Class
Public Class books
Inherits Collections.CollectionBase
Default Property Item(ByVal index As Integer) As Book
Get
Return CType(innerlist.Item(index), Book)
End Get
Set(ByVal Value As Book)
innerlist.Item(index) = Value
End Set
End Property
Sub add(ByVal value As Book)
innerlist.Add(value)
End Sub
End Class
I then create a form, add a dropdownlist
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim objBooks As books = New books()
objBooks.add(New Book("Book #1"))
objBooks.add(New Book("Book #2"))
objBooks.add(New Book("Book #3"))
objBooks.add(New Book("Book #4"))
objBooks.add(New Book("Book #5"))
DropDownList1.DataSource = objBooks
DropDownList1.DataTextField = "BookName"
DropDownList1.DataBind()
End Sub
And i get this error
DataBinder.Eval: 'Website.Products+Book' does not contain a property with
the name BookName.
When i access the object manually it works
textbox1.text = objBooks.Item(0).BookName: Does work
textbox1.text = objBooks(0).BookName: Does work
its not working.
Class Book
Public BookName As String
Sub New(ByVal lBookName As String)
Me.BookName = BookName
End Sub
End Class
Public Class books
Inherits Collections.CollectionBase
Default Property Item(ByVal index As Integer) As Book
Get
Return CType(innerlist.Item(index), Book)
End Get
Set(ByVal Value As Book)
innerlist.Item(index) = Value
End Set
End Property
Sub add(ByVal value As Book)
innerlist.Add(value)
End Sub
End Class
I then create a form, add a dropdownlist
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim objBooks As books = New books()
objBooks.add(New Book("Book #1"))
objBooks.add(New Book("Book #2"))
objBooks.add(New Book("Book #3"))
objBooks.add(New Book("Book #4"))
objBooks.add(New Book("Book #5"))
DropDownList1.DataSource = objBooks
DropDownList1.DataTextField = "BookName"
DropDownList1.DataBind()
End Sub
And i get this error
DataBinder.Eval: 'Website.Products+Book' does not contain a property with
the name BookName.
When i access the object manually it works
textbox1.text = objBooks.Item(0).BookName: Does work
textbox1.text = objBooks(0).BookName: Does work