本文整理匯總了VB.NET中System.Web.UI.DataSourceView類的典型用法代碼示例。如果您正苦於以下問題:VB.NET DataSourceView類的具體用法?VB.NET DataSourceView怎麽用?VB.NET DataSourceView使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DataSourceView類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: CsvDataSourceView
' 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