I am trying to implement the sort event in data grid. I set the data grid's
AllowSorting property = True. I implement the following code that should be
the event will fire when the user click any of the columns in the table:
Private Sub dgReport1_SortC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridSortCommand EventArgs) Handles
dgReport1.SortC ommand
Dim sortOrder As String = e.SortExpressio n.ToString()
Response.Write( sortOrder)
Dim ds As New DataSet
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView. Sort = sortOrder
dgReport1.DataS ource = ds.Tables(0).De faultView
dgReport1.DataB ind()
End Sub
When I click any of the columns in the table, it throw the following run
time error on line: Dim dt As DataTable = ds.Tables(0).
Run-time error
============
Cannot find table 0.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.IndexOut OfRangeExceptio n: Cannot find table 0.
I have no idea why table 0 has problem. Because I am able to get the table
as folows:
Dim dt As DataTable = ds.Tables(0)
dgReport1.DataS ource = dt
dgReport1.DataB ind()
Please advise! Thanks !!