Databinding with Sortedlist

G

Guest

Hi Guys,

I have a sortedlist which holds a group of "CartItem" items. following is
the CartItem class:

Public Class CartItem
Public ProdID As Integer
Public Name As String
Public Price As Decimal
Public Quantity As Integer
End Class

I have a datalist control and want to bind a label to the Name property of
the CartItem(s) in the sortedlist - the result shoud be that for each item in
the sorted list will create a new entry in the datalist control with the data
in the Name property showing in the label.

My binding sub:
Dim ShoppingCart as sortedlist = Session("Cart")
dlsCart.DataSource = ShoppingCart.Values
dlsCart.DataBind()

The label text property binding string:
DataBinder.Eval(Container.DataItem, "Name")


When I run this, I get the followig exception:

ExTYPE: System.Web.HttpException
MESSAGE: DataBinder.Eval: 'myLNF.CartItem' does not contain a property
with the name Name.


What am I doing wrong?
 
K

Ken Tucker [MVP]

Hi,

When you databind to a collection you must bind to a property.
Change you class to this.

Public Class CartItem
Private mProdID As Integer
Private mName As String
Private mPrice As Decimal
Private mQuantity As Integer

Public Property ProdID() As Integer
Get
Return mProdID
End Get
Set(ByVal value As Integer)
mProdID = value
End Set
End Property

Public Property Name() As String
Get
Return mName
End Get
Set(ByVal value As String)
mName = value
End Set
End Property

Public Property Price() As Decimal
Get
Return mPrice
End Get
Set(ByVal value As Decimal)
mPrice = value
End Set
End Property

Public Property Quanity() As Integer
Get
Return mQuantity
End Get
Set(ByVal value As Integer)
mquanity = value
End Set
End Property
End Class

Ken
-----------------
Hi Guys,

I have a sortedlist which holds a group of "CartItem" items. following is
the CartItem class:

Public Class CartItem
Public ProdID As Integer
Public Name As String
Public Price As Decimal
Public Quantity As Integer
End Class

I have a datalist control and want to bind a label to the Name property of
the CartItem(s) in the sortedlist - the result shoud be that for each item
in
the sorted list will create a new entry in the datalist control with the
data
in the Name property showing in the label.

My binding sub:
Dim ShoppingCart as sortedlist = Session("Cart")
dlsCart.DataSource = ShoppingCart.Values
dlsCart.DataBind()

The label text property binding string:
DataBinder.Eval(Container.DataItem, "Name")


When I run this, I get the followig exception:

ExTYPE: System.Web.HttpException
MESSAGE: DataBinder.Eval: 'myLNF.CartItem' does not contain a property
with the name Name.


What am I doing wrong?
 

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

Top