DataSourceCollection Class
Represents a collection of IDataSource interfaces.
System.Object
System.Collections.CollectionBase
Microsoft.SharePoint.WebControls.DataSourceCollection
System.Collections.CollectionBase
Microsoft.SharePoint.WebControls.DataSourceCollection
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
DataSourceCollection
Description
The Microsoft.SharePoint.WebControls.DataSourceCollection inherits from the System.Collections.CollectionBase which provides the required mechanisms to produce a strongly typed collection of objects. In the DataSourceCollection class, the collection type is of System.Web.UI.IDataSource which represents an abstract datasource that we can couple with an arbitrary control that accepts databinding.
The DataSourceCollection contains minimal implementation, implementing the IList.Add interface method which will resize the IDataSource array for last object insertation when adding IDataSource objects. As well, there is an indexer provided in order for the collection of IDataSource objects to be indexed in the same way as an array. By doing so, we can simply use the index position in order to reference objects in the collection in order for arbitrary returns.
The Usage Scenario
The primary usage of DataSourceCollection is internal, having heavy representation in data display pieces such as Microsoft.SharePoint.WebPartPages.DataFormWebPart. However, since it represents a strongly typed collection of IDataSource objects you can use it to represent an orthodox typed list of datasources as a data bindable class.
In the below, I am creating a new global DataSourceCollection, and demonstrating the two pieces discussed in the above, adding a new IDataSource object to the collection, and then using a generic indexing method to expose a particular IDataSource object and return it.
C# Code Example
private static DataSourceCollection _sourceCollection;
private static void AddMyDataSource(IDataSource source)
{
_sourceCollection.Add(source);
}
private IDataSource ReturnFromIndexer(int index)
{
return _sourceCollection[index];
}
Visual Basic .NET Code Example
Private Shared _sourceCollection As DataSourceCollection
Private Shared Sub AddMyDataSource(ByVal source As IDataSource)
_sourceCollection.Add(source)
End Sub
Private Function ReturnFromIndexer(ByVal index As Integer) As IDataSource
Return _sourceCollection(index)
End Function
The Microsoft.SharePoint.WebControls.DataSourceCollection inherits from the System.Collections.CollectionBase which provides the required mechanisms to produce a strongly typed collection of objects. In the DataSourceCollection class, the collection type is of System.Web.UI.IDataSource which represents an abstract datasource that we can couple with an arbitrary control that accepts databinding.
The DataSourceCollection contains minimal implementation, implementing the IList.Add interface method which will resize the IDataSource array for last object insertation when adding IDataSource objects. As well, there is an indexer provided in order for the collection of IDataSource objects to be indexed in the same way as an array. By doing so, we can simply use the index position in order to reference objects in the collection in order for arbitrary returns.
The Usage Scenario
The primary usage of DataSourceCollection is internal, having heavy representation in data display pieces such as Microsoft.SharePoint.WebPartPages.DataFormWebPart. However, since it represents a strongly typed collection of IDataSource objects you can use it to represent an orthodox typed list of datasources as a data bindable class.
In the below, I am creating a new global DataSourceCollection, and demonstrating the two pieces discussed in the above, adding a new IDataSource object to the collection, and then using a generic indexing method to expose a particular IDataSource object and return it.
C# Code Example
private static DataSourceCollection _sourceCollection;
private static void AddMyDataSource(IDataSource source)
{
_sourceCollection.Add(source);
}
private IDataSource ReturnFromIndexer(int index)
{
return _sourceCollection[index];
}
Visual Basic .NET Code Example
Private Shared _sourceCollection As DataSourceCollection
Private Shared Sub AddMyDataSource(ByVal source As IDataSource)
_sourceCollection.Add(source)
End Sub
Private Function ReturnFromIndexer(ByVal index As Integer) As IDataSource
Return _sourceCollection(index)
End Function
- 6/3/2010
- Adam Buenz - MVP