DataSourceControl.GetView(String) 方法

定义

获取与数据源控件关联的指定数据源视图。Gets the named data source view associated with the data source control.

protected:
 abstract System::Web::UI::DataSourceView ^ GetView(System::String ^ viewName);
protected abstract System.Web.UI.DataSourceView GetView (string viewName);
abstract member GetView : string -> System.Web.UI.DataSourceView
Protected MustOverride Function GetView (viewName As String) As DataSourceView

参数

viewName
String

要检索的 DataSourceView 的名称。The name of the DataSourceView to retrieve. 在只支持一个视图的数据源控件(如 SqlDataSource)中,此参数会被忽略。In data source controls that support only one view, such as SqlDataSource, this parameter is ignored.

返回

返回与 DataSourceControl 关联的指定 DataSourceViewReturns the named DataSourceView associated with the DataSourceControl.

实现

示例

下面的代码示例演示如何使用扩展DataSourceControl类的数据源控件类GetView实现方法, 并返回DataSourceView类的强类型实例。The following code example demonstrates how a data source control class that extends the DataSourceControl class implements the GetView method, returning a strongly typed instance of the DataSourceView class. 由于数据源控件只支持一个视图, 因此它将忽略名称并返回一个名为的视图, 其默认视图名称为。Because the data source control supports only one view, it ignores the name and returns a view named with the default view name. 此代码示例是为DataSourceControl类提供的更大示例的一部分。This code example is part of a larger example provided for the DataSourceControl class.

// Return a strongly typed view for the current data source control.
private CsvDataSourceView view = null;
protected override DataSourceView GetView(string viewName) {
    if (null == view) {
        view = new CsvDataSourceView(this, String.Empty);
    }
    return view;
}
' Return a strongly typed view for the current data source control.
Private view As CsvDataSourceView = Nothing

Protected Overrides Function GetView(viewName As String) As DataSourceView
   If view Is Nothing Then
      view = New CsvDataSourceView(Me, String.Empty)
   End If
   Return view
End Function 'GetView

注解

可以通过调用GetViewNames方法来枚举当前与数据源控件关联的一组视图。You can enumerate through the set of views currently associated with the data source control by calling the GetViewNames method.

数据源控件类可支持其基础数据的一个或多个视图。Data source control classes can support one or more views on their underlying data. 这些视图由DataSourceView类的实例表示。These views are represented by instances of the DataSourceView class. 数据源视图定义数据源控件的功能, 执行从基础数据存储区中检索数据所需的所有工作, 并执行排序、插入、删除和更新等操作。The data source view defines the capabilities of a data source control, does all the work necessary to retrieve data from the underlying data store, and performs operations such as sorting, inserting, deleting, and updating.

备注

类的默认实现返回nullDataSourceControlThe DataSourceControl class's default implementation returns null. 如果扩展DataSourceControl类, 请GetView重写方法以返回指定DataSourceView的对象。If you extend the DataSourceControl class, override the GetView method to return the specified DataSourceView object.

适用于

另请参阅