IDataSourceProvider.GetSelectedDataSource Method
Gets a reference to the selected data source of this data source provider.
[Visual Basic] Function GetSelectedDataSource() As Object [C#] object GetSelectedDataSource(); [C++] Object* GetSelectedDataSource(); [JScript] function GetSelectedDataSource() : Object;
Return Value
The currently selected data source object of this data source provider.
Example
[Visual Basic] The following code example implements both the GetSelectedDataSource method and the GetResolvedSelectedDataSource method of the IDataSourceProvider interface. The GetSelectedDataSource method makes sure the data source associated with the control at design time is an object that implements the IEnumerable interface. This allows users to iterate through the data source.
[Visual Basic]
' Create a method that implements the
' IDataSourceProvider.GetResolvedSelectedDataSource method.
' It converts the object returned from the GetSelectedDataSource
' method into an IEnumberable object to allow iteration over
' the returned object.
Function GetResolvedSelectedDataSource() As IEnumerable _
Implements IDataSourceProvider.GetResolvedSelectedDataSource
Return CType(CType(Me, IDataSourceProvider).GetSelectedDataSource(), IEnumerable)
End Function
' Create a method that implements the
' IDataSourceProvider.GetSelectedDataSource method.
' Return the data source as an IEnumerable object,
' if possible.
Function GetSelectedDataSource() As Object _
Implements IDataSourceProvider.GetSelectedDataSource
Dim selectedDataSource As Object = Nothing
Dim dataSource As String = Nothing
Dim binding As DataBinding = DataBindings("DataSource")
If Not (binding Is Nothing) Then
dataSource = binding.Expression
End If
If Not (dataSource Is Nothing) Then
Dim componentSite As ISite = Component.Site
If Not (componentSite Is Nothing) Then
Dim container As IContainer = CType(componentSite.GetService(GetType(IContainer)), IContainer)
If Not (container Is Nothing) Then
Dim comp As IComponent = container.Components(dataSource)
If TypeOf comp Is IEnumerable Then
selectedDataSource = comp
End If
End If
End If
End If
Return selectedDataSource
End Function
[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries From Partially Trusted Code
See Also
IDataSourceProvider Interface | IDataSourceProvider Members | System.Web.UI.Design Namespace