I have a GridView control that I attach data to in the Page_Load event. I have set AllowPaging and AllowSorting to True. The data comes from an oracle database so that means that the data binding is one way. The sorting and paging of data is a two way event so I have added two events to handle this:
OnPageIndexChanging="GridView1_PageIndexChanging"
OnSorting="GridView1_Sorting"
I do not have any issues with the OnPageIndexChanging. I have a run-time error and a build error with the OnSorting event. I've commented both lines of code where the errors are occuring.
I've found lots of examples written in C-sharp that shows that a DataTable can be converted into a DataView but none of those examples, once written in VB, work. It creates the same error as above during compiling. The DataSet to a conversion to a DataTable is a runtime error and I am not sure how to fix that. it's most likely syntax since I have seen this done in C-sharp as well.
OnPageIndexChanging="GridView1_PageIndexChanging"
OnSorting="GridView1_Sorting"
I do not have any issues with the OnPageIndexChanging. I have a run-time error and a build error with the OnSorting event. I've commented both lines of code where the errors are occuring.
Code:
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
Dim dataTable As New DataTable
dataTable = GridView1.DataSource '// Unable to cast object of type 'System.Data.DataSet' to type 'System.Data.DataTable'.
If Not dataTable Is Nothing Then
Dim dataView As New DataView
'dataView = dataTable '// Value of type 'System.Data.DataTable' to type 'System.Data.DataView'.
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection)
GridView1.DataSource = dataView
GridView1.DataBind()
End If
End Sub
I've found lots of examples written in C-sharp that shows that a DataTable can be converted into a DataView but none of those examples, once written in VB, work. It creates the same error as above during compiling. The DataSet to a conversion to a DataTable is a runtime error and I am not sure how to fix that. it's most likely syntax since I have seen this done in C-sharp as well.