What I intend to do is explain each step of the process and describe what you actually need to do support data binding in a WebControl against what the MSDN sample says you have to do. For this demonstration I created a very simple control that does nothing other than expose properties that can be used to bind to a data source, a table within that data source and finally some fields that reside in that table in the same manner as a listbox.
public class SimpleDataBoundControlDesigner : ...
{
...
IEnumerable IDataSourceProvider.GetResolvedSelectedDataSource()
{
object selectedDataSource =
((IDataSourceProvider)this).GetSelectedDataSource();
DataView dataView = null;
if (selectedDataSource is DataSet)
{
DataSet dataSet = (DataSet)selectedDataSource;
DataTable dataTable = null;
if ((DataMember != null) && (DataMember.Length>0))
dataTable = dataSet.Tables[DataMember];
else
dataTable=dataSet.Tables[0];
if (dataTable!=null)
{
dataView = dataTable.DefaultView;
}
}
else if (selectedDataSource is DataTable)
{
dataView = ((DataTable)selectedDataSource).DefaultView;
}
else if (selectedDataSource is IEnumerable)
{
return selectedDataSource as IEnumerable;
}
return dataView as IEnumerable;
}
}