Hi,
I'm using a dataTable to process some data onto a webpage.
The Page_Load calls the sub that access the database and sets up a dataTable. Another sub is then called which processes the dataTable and outputs to the webpage. That all works fine.
I want to add a drop down list that has filter criteria in it. Depending on the filter selecte the dataTable is adjusted to display by name ascending, cost ascending etc.
The problem lies in the drop down list sub. A switch statement decides what the filter and sort expressions are to be based on the selected value of the list (again, this part works OK).
The problem occurs when the dataTable.Select method is called. I've debugged the code and the dataTable is empty at this point so a 'column not found' error results.
Private Sub ddlFilter_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlFilter.SelectedIndexChanged
Dim selected As Int16 = ddlFilter.SelectedValue
Dim strExp As String
Dim strSort As String
Select Case selected
Case 0
Case 1
strExp = "'cost' > 10"
strSort = "cost ASC"
Case 2
strExp = "duration > 1"
strSort = "duration ASC"
End Select
' create new dt, run filter and pass to displayDT sub
Dim dt2 As New DataTable
Dim drRows() As DataRow, singleRow As DataRow
dtRows = dt.Select(strExp, strSort)
// error occurs here
End Sub
I've tried placing dt (the dataTable) in the page declaration and as a global Dim statement (yeah, I know, bad form but I getting desperate) but the drop down list sub just can't seem to access it.
Any ideas as how to how/where the dataTable should be created to be accessible by the drop down list sub?
Help is very much appreciated,
Hericles