DataBinding In a Custom Control - 12-05-2007 , 11:38 AM
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
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 = '' ???
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
Any help or links would be very much appreciated.
Re: DataBinding In a Custom Control - 12-05-2007 , 12:49 PM
On Dec 5, 12:38 pm, thoughtcrimes <tylerxpr... (AT) gmail (DOT) com> wrote:
I don't know if the exception it throws is all that nice, so might
try, catch and throw my own if the DataValueField doesn't exist in the
If anyone has any links to good tutorials or references on building
custom WebControls please reply.
|Thread Tools||Search this Thread|