DropDownList: Complex DataBinding with Custom Business Objects

D

Dan Caron

I have an ArrayList of Custom Business Objects that I need to bind to
a DropDownList. The DataBind works, but I cannot figure out how to
have the value/text fields of the DropDownList to reference the object
properties.

For instance, assume I have an ArrayList of UserInfo classes. The
UserInfo class "has a" UserAccount, as shown in the code below. How
can I bind the DropDownList to the UserInfo.Account.FirstName
property?


---------------------------
Public Class UserInfo

Private _Username as String
Private _Account as UserAccount

Public Property Username() As String
Get
Return _Username
End Get
Set(ByVal Value As String)
_Username= Value
End Set
End Property

Public Property Account() As UserAccount
Get
Return _Account
End Get
Set(ByVal Value As UserAccount)
_Account= Value
End Set
End Property

End Class

Public Class UserAccount

Private _FirstName as String
Private _LastName as String

Public Property FirstName() As String
Get
Return _FirstName
End Get
Set(ByVal Value As String)
_FirstName= Value
End Set
End Property

Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal Value As String)
_LastName= Value
End Set
End Property

End Class
---------------------------

When I bind this to a DataGrid, it works fine:

<asp:Label ID="Label3" Runat="server" Text='<%#
CType(Container.DataItem,
Users.UserInfo).Account.FirstName%>'></asp:Label>

But I do not have this luxury when binding to a DropDownList.

-Dan
 
D

djk

Hi Dan,

I'm facing exactly the same problem and I'm unable to solve it. I was able
to find only one peace of information in the Programming ASP.NET (MSPress)
book and it says that only simple strings are allowed for those properties.

My team colleague said to me, that it seems that object properties are
accessible if you bind to control in .aspx page, but not working when you
bind from code. Strange.

Please, let me now if you figure out something.

daniel
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top