DataSourceView DataSourceView DataSourceView DataSourceView Class

Definition

Dient als Basisklasse für alle Datenquellenansichtsklassen, die die Funktionen von Datenquellensteuerelementen festlegen.Serves as the base class for all data source view classes, which define the capabilities of data source controls.

public ref class DataSourceView abstract
public abstract class DataSourceView
type DataSourceView = class
Public MustInherit Class DataSourceView
Vererbung
DataSourceViewDataSourceViewDataSourceViewDataSourceView
Abgeleitet

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die DataSourceView -Klasse erweitert wird, um eine stark typisierte Ansichts Klasse für ein Datenquellen-Steuerelement zu erstellen.The following code example demonstrates how to extend the DataSourceView class to create a strongly typed view class for a data source control. Die CsVDataSourceView -Klasse definiert die Funktionen CsvDataSource des Datenquellen-Steuer Elements und stellt eine Implementierung für Daten gebundene Steuerelemente bereit, um Daten zu verwenden, die in CSV-Dateien (Comma-Separated Value) gespeichert sind.The CsVDataSourceView class defines the capabilities of the CsvDataSource data source control and provides an implementation for data-bound controls to use data stored in comma-separated value (.csv) files. Weitere Informationen zum CsvDataSource Datenquellen-Steuerelement finden Sie in DataSourceControl der-Klasse.For more information on the CsvDataSource data source control, see the DataSourceControl class.

// The CsvDataSourceView class encapsulates the
// capabilities of the CsvDataSource data source control.
public class CsvDataSourceView : DataSourceView
{

    public CsvDataSourceView(IDataSource owner, string name) :base(owner, DefaultViewName) {

    }

    // The data source view is named. However, the CsvDataSource
    // only supports one view, so the name is ignored, and the
    // default name used instead.
    public static string DefaultViewName = "CommaSeparatedView";

    // The location of the .csv file.
    private string sourceFile = String.Empty;
    internal string SourceFile {
        get {
            return sourceFile;
        }
        set {
            // Use MapPath when the SourceFile is set, so that files local to the
            // current directory can be easily used.
            string mappedFileName = HttpContext.Current.Server.MapPath(value);
            sourceFile = mappedFileName;
        }
    }

    // Do not add the column names as a data row. Infer columns if the CSV file does
    // not include column names.
    private bool columns = false;
    internal bool IncludesColumnNames {
        get {
            return columns;
        }
        set {
            columns = value;
        }
    }

    // Get data from the underlying data source.
    // Build and return a DataView, regardless of mode.
    protected override IEnumerable ExecuteSelect(DataSourceSelectArguments selectArgs) {
        IEnumerable dataList = null;
        // Open the .csv file.
        if (File.Exists(this.SourceFile)) {
            DataTable data = new DataTable();

            // Open the file to read from.
            using (StreamReader sr = File.OpenText(this.SourceFile)) {
                // Parse the line
                string s = "";
                string[] dataValues;
                DataColumn col;

                // Do the following to add schema.
                dataValues = sr.ReadLine().Split(',');
                // For each token in the comma-delimited string, add a column
                // to the DataTable schema.
                foreach (string token in dataValues) {
                    col = new DataColumn(token,typeof(string));
                    data.Columns.Add(col);
                }

                // Do not add the first row as data if the CSV file includes column names.
                if (! IncludesColumnNames)
                    data.Rows.Add(CopyRowData(dataValues, data.NewRow()));

                // Do the following to add data.
                while ((s = sr.ReadLine()) != null) {
                    dataValues = s.Split(',');
                    data.Rows.Add(CopyRowData(dataValues, data.NewRow()));
                }
            }
            data.AcceptChanges();
            DataView dataView = new DataView(data);
            if (!string.IsNullOrEmpty(selectArgs.SortExpression)) {
                dataView.Sort = selectArgs.SortExpression;
            }
            dataList = dataView;
        }
        else {
            throw new System.Configuration.ConfigurationErrorsException("File not found, " + this.SourceFile);
        }

        if (null == dataList) {
            throw new InvalidOperationException("No data loaded from data source.");
        }

        return dataList;
    }

    private DataRow CopyRowData(string[] source, DataRow target) {
        try {
            for (int i = 0;i < source.Length;i++) {
                target[i] = source[i];
            }
        }
        catch (System.IndexOutOfRangeException) {
            // There are more columns in this row than
            // the original schema allows.  Stop copying
            // and return the DataRow.
            return target;
        }
        return target;
    }
    // The CsvDataSourceView does not currently
    // permit deletion. You can modify or extend
    // this sample to do so.
    public override bool CanDelete {
        get {
            return false;
        }
    }
    protected override int ExecuteDelete(IDictionary keys, IDictionary values)
    {
        throw new NotSupportedException();
    }
    // The CsvDataSourceView does not currently
    // permit insertion of a new record. You can
    // modify or extend this sample to do so.
    public override bool CanInsert {
        get {
            return false;
        }
    }
    protected override int ExecuteInsert(IDictionary values)
    {
        throw new NotSupportedException();
    }
    // The CsvDataSourceView does not currently
    // permit update operations. You can modify or
    // extend this sample to do so.
    public override bool CanUpdate {
        get {
            return false;
        }
    }
    protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
    {
        throw new NotSupportedException();
    }
}
' The CsvDataSourceView class encapsulates the
' capabilities of the CsvDataSource data source control.

Public Class CsvDataSourceView
   Inherits DataSourceView

   Public Sub New(owner As IDataSource, name As String)
       MyBase.New(owner, DefaultViewName)
   End Sub

   ' The data source view is named. However, the CsvDataSource
   ' only supports one view, so the name is ignored, and the
   ' default name used instead.
   Public Shared DefaultViewName As String = "CommaSeparatedView"

   ' The location of the .csv file.
   Private aSourceFile As String = [String].Empty

   Friend Property SourceFile() As String
      Get
         Return aSourceFile
      End Get
      Set
         ' Use MapPath when the SourceFile is set, so that files local to the
         ' current directory can be easily used.
         Dim mappedFileName As String
         mappedFileName = HttpContext.Current.Server.MapPath(value)
         aSourceFile = mappedFileName
      End Set
   End Property

   ' Do not add the column names as a data row. Infer columns if the CSV file does
   ' not include column names.
   Private columns As Boolean = False

   Friend Property IncludesColumnNames() As Boolean
      Get
         Return columns
      End Get
      Set
         columns = value
      End Set
   End Property

   ' Get data from the underlying data source.
   ' Build and return a DataView, regardless of mode.
   Protected Overrides Function ExecuteSelect(selectArgs As DataSourceSelectArguments) _
    As System.Collections.IEnumerable
      Dim dataList As IEnumerable = Nothing
      ' Open the .csv file.
      If File.Exists(Me.SourceFile) Then
         Dim data As New DataTable()

         ' Open the file to read from.
         Dim sr As StreamReader = File.OpenText(Me.SourceFile)

         Try
            ' Parse the line
            Dim dataValues() As String
            Dim col As DataColumn

            ' Do the following to add schema.
            dataValues = sr.ReadLine().Split(","c)
            ' For each token in the comma-delimited string, add a column
            ' to the DataTable schema.
            Dim token As String
            For Each token In dataValues
               col = New DataColumn(token, System.Type.GetType("System.String"))
               data.Columns.Add(col)
            Next token

            ' Do not add the first row as data if the CSV file includes column names.
            If Not IncludesColumnNames Then
               data.Rows.Add(CopyRowData(dataValues, data.NewRow()))
            End If

            ' Do the following to add data.
            Dim s As String
            Do
               s = sr.ReadLine()
               If Not s Is Nothing Then
                   dataValues = s.Split(","c)
                   data.Rows.Add(CopyRowData(dataValues, data.NewRow()))
               End If
            Loop Until s Is Nothing

         Finally
            sr.Close()
         End Try

         data.AcceptChanges()
         Dim dataView As New DataView(data)
         If Not selectArgs.SortExpression Is String.Empty Then
             dataView.Sort = selectArgs.SortExpression
         End If
         dataList = dataView
      Else
         Throw New System.Configuration.ConfigurationErrorsException("File not found, " + Me.SourceFile)
      End If

      If dataList is Nothing Then
         Throw New InvalidOperationException("No data loaded from data source.")
      End If

      Return dataList
   End Function 'ExecuteSelect


   Private Function CopyRowData([source]() As String, target As DataRow) As DataRow
      Try
         Dim i As Integer
         For i = 0 To [source].Length - 1
            target(i) = [source](i)
         Next i
      Catch iore As IndexOutOfRangeException
         ' There are more columns in this row than
         ' the original schema allows.  Stop copying
         ' and return the DataRow.
         Return target
      End Try
      Return target
   End Function 'CopyRowData

   ' The CsvDataSourceView does not currently
   ' permit deletion. You can modify or extend
   ' this sample to do so.
   Public Overrides ReadOnly Property CanDelete() As Boolean
      Get
         Return False
      End Get
   End Property

   Protected Overrides Function ExecuteDelete(keys As IDictionary, values As IDictionary) As Integer
      Throw New NotSupportedException()
   End Function 'ExecuteDelete

   ' The CsvDataSourceView does not currently
   ' permit insertion of a new record. You can
   ' modify or extend this sample to do so.
   Public Overrides ReadOnly Property CanInsert() As Boolean
      Get
         Return False
      End Get
   End Property

   Protected Overrides Function ExecuteInsert(values As IDictionary) As Integer
      Throw New NotSupportedException()
   End Function 'ExecuteInsert

   ' The CsvDataSourceView does not currently
   ' permit update operations. You can modify or
   ' extend this sample to do so.
   Public Overrides ReadOnly Property CanUpdate() As Boolean
      Get
         Return False
      End Get
   End Property

   Protected Overrides Function ExecuteUpdate(keys As IDictionary, _
                                              values As IDictionary, _
                                              oldValues As IDictionary) As Integer
      Throw New NotSupportedException()
   End Function 'ExecuteUpdate

End Class 'CsvDataSourceView

Hinweise

ASP.NET unterstützt eine Daten Bindungs Architektur, mit der Webserver Steuerelemente einheitlich an Daten gebunden werden können.ASP.NET supports a data-binding architecture that enables Web server controls to bind to data in a consistent fashion. Webserver Steuerelemente, die an Daten gebunden werden, werden als Daten gebundene Steuerelemente bezeichnet, und die Klassen, die diese Bindung vereinfachen, werden als Datenquellen-Steuerelemente bezeichnet.Web server controls that bind to data are referred to as data-bound controls, and the classes that facilitate that binding are called data source controls. Datenquellensteuerelemente können jede beliebige Datenquelle darstellen: eine relationale Datenbank, eine Datei, einen Stream, ein Geschäftsobjekt usw.Data source controls can represent any data source: a relational database, a file, a stream, a business object, and so on. Datenquellen-Steuerelemente präsentieren Daten auf konsistente Weise für Daten gebundene Steuerelemente, unabhängig von der Quelle oder dem Format der zugrunde liegenden Daten.Data source controls present data in a consistent way to data-bound controls, regardless of the source or format of the underlying data.

Sie verwenden die Datenquellen Steuerelemente, die mit ASP.NET bereitgestellt SqlDataSourcewerden AccessDataSource, einschließlich XmlDataSource, und, um die meisten Webentwicklungs Aufgaben auszuführen.You use the data source controls that are provided with ASP.NET, including SqlDataSource, AccessDataSource, and XmlDataSource, to perform most Web development tasks. Sie verwenden die Basis DataSourceControl - DataSourceView und-Klassen, wenn Sie Ihr eigenes benutzerdefiniertes Datenquellen-Steuerelement implementieren möchten.You use the base DataSourceControl and DataSourceView classes when you want to implement your own custom data source control.

Sie können sich ein Datenquellen-Steuerelement als die Kombination IDataSource aus dem-Objekt und den zugehörigen Daten Listen vorstellen, die als Datenquellen Sichten bezeichnet werden.You can think of a data source control as the combination of the IDataSource object and its associated lists of data, called data source views. Jede Datenliste wird durch ein DataSourceView -Objekt dargestellt.Each list of data is represented by a DataSourceView object. Die DataSourceView -Klasse ist die Basisklasse für alle Datenquellen Sichten oder Listen von Daten, die Datenquellen Steuerelementen zugeordnet sind.The DataSourceView class is the base class for all data source views, or lists of data, associated with data source controls. Datenquellen Sichten definieren die Funktionen eines Datenquellen-Steuer Elements.Data source views define the capabilities of a data source control. Da der zugrunde liegende Datenspeicher eine oder mehrere Listen mit Daten enthält, ist ein Datenquellen-Steuerelement immer einer oder mehreren benannten Datenquellen Sichten zugeordnet.Because the underlying data storage contains one or more lists of data, a data source control is always associated with one or more named data source views. Das Datenquellen-Steuerelement GetViewNames verwendet die-Methode, um die Datenquellen Sichten aufzulisten, die derzeit dem Datenquellen GetView -Steuerelement zugeordnet sind, und die-Methode, um eine bestimmte Instanz der Datenquellen Sicht nach Namen abzurufen.The data source control uses the GetViewNames method to enumerate the data source views currently associated with the data source control and the GetView method to retrieve a specific data source view instance by name.

Alle DataSourceView -Objekte unterstützen das Abrufen von Daten aus der zugrunde ExecuteSelect liegenden Datenquelle mithilfe der-Methode.All DataSourceView objects support data retrieval from the underlying data source using the ExecuteSelect method. Alle Sichten unterstützen optional einen grundlegenden Satz von Vorgängen, einschließlich ExecuteInsertOperationen ExecuteUpdatewie, ExecuteDeleteund.All views optionally support a basic set of operations, including operations such as ExecuteInsert, ExecuteUpdate, and ExecuteDelete. Ein Daten gebundenes Steuerelement kann die Funktionen eines Datenquellen-Steuer Elements ermitteln, indem eine zugeordnete Datenquellen Sicht GetView mithilfe GetViewNames der-Methode und der-Methode abgerufen wird und die Sicht zur Entwurfszeit oder zur Laufzeit abgefragt wird.A data-bound control can discover the capabilities of a data source control by retrieving an associated data source view using the GetView and GetViewNames methods, and by querying the view at design time or run time.

Konstruktoren

DataSourceView(IDataSource, String) DataSourceView(IDataSource, String) DataSourceView(IDataSource, String) DataSourceView(IDataSource, String)

Initialisiert eine neue Instanz der DataSourceView-Klasse.Initializes a new instance of the DataSourceView class.

Eigenschaften

CanDelete CanDelete CanDelete CanDelete

Ruft einen Wert ab, der angibt, ob das DataSourceView-Objekt, das dem aktuellen DataSourceControl-Objekt zugeordnet ist, den ExecuteDelete(IDictionary, IDictionary)-Vorgang unterstützt.Gets a value indicating whether the DataSourceView object associated with the current DataSourceControl object supports the ExecuteDelete(IDictionary, IDictionary) operation.

CanInsert CanInsert CanInsert CanInsert

Ruft einen Wert ab, der angibt, ob das DataSourceView-Objekt, das dem aktuellen DataSourceControl-Objekt zugeordnet ist, den ExecuteInsert(IDictionary)-Vorgang unterstützt.Gets a value indicating whether the DataSourceView object associated with the current DataSourceControl object supports the ExecuteInsert(IDictionary) operation.

CanPage CanPage CanPage CanPage

Ruft einen Wert ab, der angibt, ob das DataSourceView-Objekt, das dem aktuellen DataSourceControl-Objekt zugeordnet ist, Paging durch die Daten unterstützt, die von der ExecuteSelect(DataSourceSelectArguments)-Methode abgerufen wurden.Gets a value indicating whether the DataSourceView object associated with the current DataSourceControl object supports paging through the data retrieved by the ExecuteSelect(DataSourceSelectArguments) method.

CanRetrieveTotalRowCount CanRetrieveTotalRowCount CanRetrieveTotalRowCount CanRetrieveTotalRowCount

Ruft einen Wert ab, der angibt, ob das DataSourceView-Objekt, das dem aktuellen DataSourceControl-Objekt zugeordnet ist, das Abrufen der Gesamtanzahl der Datenzeilen (anstelle der Daten) unterstützt.Gets a value indicating whether the DataSourceView object associated with the current DataSourceControl object supports retrieving the total number of data rows, instead of the data.

CanSort CanSort CanSort CanSort

Ruft einen Wert ab, der angibt, ob das DataSourceView-Objekt, das dem aktuellen DataSourceControl-Objekt zugeordnet ist, eine sortierte Ansicht der zugrunde liegenden Datenquelle unterstützt.Gets a value indicating whether the DataSourceView object associated with the current DataSourceControl object supports a sorted view on the underlying data source.

CanUpdate CanUpdate CanUpdate CanUpdate

Ruft einen Wert ab, der angibt, ob das DataSourceView-Objekt, das dem aktuellen DataSourceControl-Objekt zugeordnet ist, den ExecuteUpdate(IDictionary, IDictionary, IDictionary)-Vorgang unterstützt.Gets a value indicating whether the DataSourceView object associated with the current DataSourceControl object supports the ExecuteUpdate(IDictionary, IDictionary, IDictionary) operation.

Events Events Events Events

Ruft eine Liste von Ereignishandlerdelegaten für die Datenquellenansicht ab.Gets a list of event-handler delegates for the data source view.

Name Name Name Name

Ruft den Namen der Datenquellenansicht ab.Gets the name of the data source view.

Methoden

CanExecute(String) CanExecute(String) CanExecute(String) CanExecute(String)

Bestimmt, ob der angegebene Befehl ausgeführt werden kann.Determines whether the specified command can be executed.

Delete(IDictionary, IDictionary, DataSourceViewOperationCallback) Delete(IDictionary, IDictionary, DataSourceViewOperationCallback) Delete(IDictionary, IDictionary, DataSourceViewOperationCallback) Delete(IDictionary, IDictionary, DataSourceViewOperationCallback)

Führt einen asynchronen Löschvorgang in der Liste der Daten aus, die das DataSourceView-Objekt darstellt.Performs an asynchronous delete operation on the list of data that the DataSourceView object represents.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExecuteCommand(String, IDictionary, IDictionary) ExecuteCommand(String, IDictionary, IDictionary) ExecuteCommand(String, IDictionary, IDictionary) ExecuteCommand(String, IDictionary, IDictionary)

Führt den angegebenen Befehl aus.Executes the specified command.

ExecuteCommand(String, IDictionary, IDictionary, DataSourceViewOperationCallback) ExecuteCommand(String, IDictionary, IDictionary, DataSourceViewOperationCallback) ExecuteCommand(String, IDictionary, IDictionary, DataSourceViewOperationCallback) ExecuteCommand(String, IDictionary, IDictionary, DataSourceViewOperationCallback)

Führt den angegebenen Befehl aus.Executes the specified command.

ExecuteDelete(IDictionary, IDictionary) ExecuteDelete(IDictionary, IDictionary) ExecuteDelete(IDictionary, IDictionary) ExecuteDelete(IDictionary, IDictionary)

Führt einen Löschvorgang in der Liste der Daten aus, die das DataSourceView-Objekt darstellt.Performs a delete operation on the list of data that the DataSourceView object represents.

ExecuteInsert(IDictionary) ExecuteInsert(IDictionary) ExecuteInsert(IDictionary) ExecuteInsert(IDictionary)

Führt einen Einfügevorgang in der Liste der Daten aus, die das DataSourceView-Objekt darstellt.Performs an insert operation on the list of data that the DataSourceView object represents.

ExecuteSelect(DataSourceSelectArguments) ExecuteSelect(DataSourceSelectArguments) ExecuteSelect(DataSourceSelectArguments) ExecuteSelect(DataSourceSelectArguments)

Ruft eine Liste der Daten aus dem zugrunde liegenden Datenspeicher ab.Gets a list of data from the underlying data storage.

ExecuteUpdate(IDictionary, IDictionary, IDictionary) ExecuteUpdate(IDictionary, IDictionary, IDictionary) ExecuteUpdate(IDictionary, IDictionary, IDictionary) ExecuteUpdate(IDictionary, IDictionary, IDictionary)

Führt einen Aktualisierungsvorgang in der Liste der Daten aus, die das DataSourceView-Objekt darstellt.Performs an update operation on the list of data that the DataSourceView object represents.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Standardhashfunktion.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Inherited from Object)
Insert(IDictionary, DataSourceViewOperationCallback) Insert(IDictionary, DataSourceViewOperationCallback) Insert(IDictionary, DataSourceViewOperationCallback) Insert(IDictionary, DataSourceViewOperationCallback)

Führt einen asynchronen Einfügevorgang in der Liste der Daten aus, die das DataSourceView-Objekt darstellt.Performs an asynchronous insert operation on the list of data that the DataSourceView object represents.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
OnDataSourceViewChanged(EventArgs) OnDataSourceViewChanged(EventArgs) OnDataSourceViewChanged(EventArgs) OnDataSourceViewChanged(EventArgs)

Löst das DataSourceViewChanged-Ereignis aus.Raises the DataSourceViewChanged event.

RaiseUnsupportedCapabilityError(DataSourceCapabilities) RaiseUnsupportedCapabilityError(DataSourceCapabilities) RaiseUnsupportedCapabilityError(DataSourceCapabilities) RaiseUnsupportedCapabilityError(DataSourceCapabilities)

Durch die RaiseUnsupportedCapabilitiesError(DataSourceView)-Methode aufgerufen, um die für einen ExecuteSelect(DataSourceSelectArguments)-Vorgang erforderlichen Funktionen mit denen zu vergleichen, die die Ansicht unterstützt.Called by the RaiseUnsupportedCapabilitiesError(DataSourceView) method to compare the capabilities requested for an ExecuteSelect(DataSourceSelectArguments) operation against those that the view supports.

Select(DataSourceSelectArguments, DataSourceViewSelectCallback) Select(DataSourceSelectArguments, DataSourceViewSelectCallback) Select(DataSourceSelectArguments, DataSourceViewSelectCallback) Select(DataSourceSelectArguments, DataSourceViewSelectCallback)

Ruft asynchron eine Liste der Daten aus dem zugrunde liegenden Datenspeicher ab.Gets a list of data asynchronously from the underlying data storage.

ToString() ToString() ToString() ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)
Update(IDictionary, IDictionary, IDictionary, DataSourceViewOperationCallback) Update(IDictionary, IDictionary, IDictionary, DataSourceViewOperationCallback) Update(IDictionary, IDictionary, IDictionary, DataSourceViewOperationCallback) Update(IDictionary, IDictionary, IDictionary, DataSourceViewOperationCallback)

Führt einen asynchronen Aktualisierungsvorgang in der Liste der Daten aus, die das DataSourceView-Objekt darstellt.Performs an asynchronous update operation on the list of data that the DataSourceView object represents.

Ereignisse

DataSourceViewChanged DataSourceViewChanged DataSourceViewChanged DataSourceViewChanged

Tritt ein, wenn sich die Datenquellenansicht geändert hat.Occurs when the data source view has changed.

Gilt für:

Siehe auch