Private _ConnectionString As String = String.Empty
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PopulateGridViewWithoutDataView()
PopulateGridViewWithDataView()
End Sub
Private Sub PopulateGridViewWithoutDataView()
Try
Dim dtOriginalProductList As DataTable = GetListOfProducts.Tables(0) 'Get the datatable of products
Dim drProducts() As DataRow = dtOriginalProductList.Select("1=1", "ListPrice DESC") 'select 1=1 brings back all rows, and then just sort
Dim dtNewProductList As DataTable = dtOriginalProductList.Clone 'create datatable to hold new list (to bind to gridview)
For Each drProduct As DataRow In drProducts 'Put new list of data into the new datatable
dtNewProductList.ImportRow(drProduct)
Next
gvProductsWithoutDataView.DataSource = dtNewProductList 'Set
gvProductsWithoutDataView.DataBind() 'Bind
Catch ex As Exception
'Error handling code here
End Try
End Sub
Private Sub PopulateGridViewWithDataView()
Dim dtOriginalProductList As DataTable = GetListOfProducts.Tables(0) 'Get the datatable of products
Dim dvProductList As New DataView 'Create DataView
dvProductList.Table = dtOriginalProductList 'Load DataTable
dvProductList.Sort = "ListPrice DESC" 'Sort Property
gvProductsWithDataView.DataSource = dvProductList 'Set
gvProductsWithDataView.DataBind() 'Bind
End Sub
Public Function GetListOfProducts() As DataSet
Dim oDS As New DataSet
Try
_ConnectionString = ConfigurationManager.ConnectionStrings("DefaultConnectionString").ConnectionString
oDS = DataAccess.SqlHelper.ExecuteDataset(_ConnectionString, CommandType.Text, "SELECT ProductID, Name, ProductNumber, StandardCost, ListPrice FROM Production.Product")
Return oDS
Catch ex As Exception
Throw ex
Finally
End Try
End Function