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
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