473,408 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Help: Data Binding to Custom Collection

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

Nov 17 '05 #1
2 1532
The error message tells you what it is looking for. You have to make
BookName a property.

L.L.

"Shrage Smilowitz" <mi***********@hotmail.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #2
:-) Thanks a million! I have ben working on it a whole day, i didn't realize
that, i tought a public variable is the same think as a property. Thanks
Again!

"L. L." <ll**@cyence.com> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
The error message tells you what it is looking for. You have to make
BookName a property.

L.L.

"Shrage Smilowitz" <mi***********@hotmail.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
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


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CGuy | last post by:
URGENT HELP REQUIRED FROM GURUS Hi, I have a custom object that implements ICollection and IListSource. This object has also an enumerator defined for it which implements IEnumerator and...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
18
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.