T
thoughtcrimes
Hello:
I am building a DropDownList-type control. I opted for inheriting just
the WebControl class instead of DropDownList class because the child
controls and the rendered HTML will be quite different.
I have an IEnumerable DataSource and the properties DataValueField and
DataTextField which are just strings of the name of properties in
whatever type of objects are in the DataSource. What I would like to
do is loop through the DataSource and create ListItems by copying over
the DataValueFields and DataTextFields to the ListItems' Value and
Text Fields, but I don't know how to do this.
So if I had a class "Cola" with properties "ColaId" and "ColaName" and
set the DataSource to a List (Of Cola) and the DataValueField to
"ColaId" and the DataTextField to "ColaName", and I ran the following
code:
----------
Dim items As New ArrayList()
Dim data As IEnumerable = GetDataSource()
For Each dataItem As Object In data
Dim listItem As New myListItem
listItem.Value = '' ???
listItem.Text = '' ???
Next
Dim itemsCollection As New myListItemsCollection(items)
----------
I would want to end up with an myListItemsCollection containing
several myListItems that had Values and Text s from the List (Of
Cola).
Any help or links would be very much appreciated.
Thanks,
-Tyler
I am building a DropDownList-type control. I opted for inheriting just
the WebControl class instead of DropDownList class because the child
controls and the rendered HTML will be quite different.
I have an IEnumerable DataSource and the properties DataValueField and
DataTextField which are just strings of the name of properties in
whatever type of objects are in the DataSource. What I would like to
do is loop through the DataSource and create ListItems by copying over
the DataValueFields and DataTextFields to the ListItems' Value and
Text Fields, but I don't know how to do this.
So if I had a class "Cola" with properties "ColaId" and "ColaName" and
set the DataSource to a List (Of Cola) and the DataValueField to
"ColaId" and the DataTextField to "ColaName", and I ran the following
code:
----------
Dim items As New ArrayList()
Dim data As IEnumerable = GetDataSource()
For Each dataItem As Object In data
Dim listItem As New myListItem
listItem.Value = '' ???
listItem.Text = '' ???
Next
Dim itemsCollection As New myListItemsCollection(items)
----------
I would want to end up with an myListItemsCollection containing
several myListItems that had Values and Text s from the List (Of
Cola).
Any help or links would be very much appreciated.
Thanks,
-Tyler