protected virtual IDataSource GetDataSource()
{
if (this.IsBoundUsingDataSourceID)
{
Control ctrl = Utilities.ControlUtils.FindControl(this, this.DataSourceID);
if (ctrl == null)
{
throw new HttpException("A IDatasource Control with the ID '{0}' could not be found.".FormatWith(this.DataSourceID));
}
if (!(ctrl is IDataSource))
{
throw new HttpException("The control with ID '{0}' is not a control of type IDataSource.".FormatWith(this.DataSourceID));
}
return (IDataSource)ctrl;
}
if (this.DataSource == null)
{
return null;
}
IDataSource ds = this.DataSource as IDataSource;
if (ds != null)
{
return ds;
}
IEnumerable ie = ResolveDataSource(DataSource, DataMember);
if (ie != null)
{
return new CollectionDataSource(ie);
}
throw new HttpException("Unexpected data source type: {0}".FormatWith(DataSource.GetType()));
}