We have a desktop application that is being ported to web, and while some of the code has to be redeveloped from the ground up, there is alot that won't need to be (I hope). In the desktop application we were able to populate comboboxes and listboxes with custom objects by simply overriding the ToString method.
For example:
Web applications however are a completely different thing, I can't add an object to the asp listbox control and I can't explicitly store an asp listboxitem into a class.
The problem comes in when you start having larger classes with several properties that are not visible client-side because ToString sets what text of the control will be only, other items are never utilized and seemingly cannot be retrieved. We can set a value in the listbox, but if there are half a dozen proerties that need to make the round trip, it won't work.
Winforms stores the object then sets the ToString value in the listbox and all class data is preserved. Is there something I am missing? Can this be done with Telerik Rad controls or will I need to completely rethink how to handle this issue? ToString and Value are simply not enough fields to work.
For example:
Public
Class
SimpleItem
Private
_id
As
Integer
Private
_name
As
String
Private
_birthdate
As
Date
Public
Sub
New
(
ByVal
id
As
Integer
,
ByVal
Name
As
String
,
ByVal
Birthday
As
Date
)
_name = Name
_id = id
_birthdate = Birthday
End
Sub
Public
ReadOnly
Property
Age()
As
Integer
Get
Return
If
((
Date
.Today.Month >= _birthdate.Month)
And
(
Date
.Today.Day >= _birthdate.Day),
Date
.Today.Year - _birthdate.Year,
Date
.Today.Year - _birthdate.Year - 1)
End
Get
End
Property
Public
ReadOnly
Property
Name()
As
Integer
Get
Return
_name
End
Get
End
Property
Public
Overrides
Function
ToString()
As
String
Return
String
.Format(
"{0}, Age: {1}"
, _name,
Me
.Age)
End
Function
End
Class
'Add several unique items to listbox
MyListBox.Items.Add(
New
SimpleItem(12,
"John Doe"
,
New
Date
(1960, 12, 17)))
'Loop through items
For
Each
item
As
SimpleItem in MyListbox.Items
If
(item.Age >= 21)
MsgBox (item.Name &
" can purchase alcoholic beverages.")
End
If
Next
item
Web applications however are a completely different thing, I can't add an object to the asp listbox control and I can't explicitly store an asp listboxitem into a class.
The problem comes in when you start having larger classes with several properties that are not visible client-side because ToString sets what text of the control will be only, other items are never utilized and seemingly cannot be retrieved. We can set a value in the listbox, but if there are half a dozen proerties that need to make the round trip, it won't work.
Winforms stores the object then sets the ToString value in the listbox and all class data is preserved. Is there something I am missing? Can this be done with Telerik Rad controls or will I need to completely rethink how to handle this issue? ToString and Value are simply not enough fields to work.