I query a table that creates a dataset in "lastname" order. I then bind the table to a datagrid that displays the data in the proper "lastname" order. When I move to a "record layout" page I create a datatable from the Cached table and I want to navigate is "lastname" order. Instead, the navigation is in "emp_id" order.
GRID
EMP_ID LASTNAME FIRSTNAME
5 A JOAN
3 B JOHN
1 C KEVIN
AFTER RESTORING CACHE IN RECORD LAYOUT I GET THIS ORDER
EMP_ID LASTNAME FIRSTNAME
1 C KEVIN
3 B JOHN
5 A JOAN
Page 1 (contains grid)
strSQL = "SELECT emp_id, lastname,firstname"
strSQL += " FROM EMPLOYEES ORDER BY lastname"
dstSearch = New DataSet()
conPubs = New OleDbConnection(connection_string)
dadSearch = New OleDbDataAdapter(strSQL, conPubs)
dadSearch.Fill(dstSearch, "C_EMPLOYEES")
dtblSearch = dstSearch.Tables("C_EMPLOYEES")
dgrdEmployees.DataSource = dstSearch
dgrdEmployees.DataBind()
Cache("CACHED_TABLE") = dtblSearch
Step 2. On the grid I have a "Select" link that shows a page with detail about the employee. On the forms are <Next> and <Previous> buttons. When I press the next and prev buttons, the cached data moves in "emp_id" order rather than last name.
Page 2 Record Layout
Sub Record_View()
Dim dtblTemp AS DataTable
Dim dvwRecord AS DataView
Dim RowIndex AS Integer
Dim numrows AS INTEGER
SESSION("PREV") = 0
SESSION("NEXT") = 0
SESSION("FIRST") = 0
SESSION("LAST") = 0
dtblTemp = Cache("CACHED_TABLE")
numrows = dtblTemp.Rows.Count-1
SESSION("FIRST") = dtblTemp.Rows(0).Item("EMP_ID")
SESSION("LAST") = dtblTemp.Rows(numrows).Item("EMP_ID"))
dvwRecord = dtblTemp.DefaultView()
dvwRecord.Sort = Session("LASTNAME")
RowIndex = dvwRecord.Find("EMP_ID"))
IF RowIndex <> -1 THEN
IF RowIndex > 0 THEN
SESSION("PREV") = dvwRecord(RowIndex-1).Row(EMP_ID"))
END IF
IF RowIndex <> dtblTemp.Rows.Count-1 THEN
SESSION("NEXT") = dvwRecord(RowIndex+1).Row("EMP_ID"))
END IF
END SUB
GRID
EMP_ID LASTNAME FIRSTNAME
5 A JOAN
3 B JOHN
1 C KEVIN
AFTER RESTORING CACHE IN RECORD LAYOUT I GET THIS ORDER
EMP_ID LASTNAME FIRSTNAME
1 C KEVIN
3 B JOHN
5 A JOAN
Page 1 (contains grid)
strSQL = "SELECT emp_id, lastname,firstname"
strSQL += " FROM EMPLOYEES ORDER BY lastname"
dstSearch = New DataSet()
conPubs = New OleDbConnection(connection_string)
dadSearch = New OleDbDataAdapter(strSQL, conPubs)
dadSearch.Fill(dstSearch, "C_EMPLOYEES")
dtblSearch = dstSearch.Tables("C_EMPLOYEES")
dgrdEmployees.DataSource = dstSearch
dgrdEmployees.DataBind()
Cache("CACHED_TABLE") = dtblSearch
Step 2. On the grid I have a "Select" link that shows a page with detail about the employee. On the forms are <Next> and <Previous> buttons. When I press the next and prev buttons, the cached data moves in "emp_id" order rather than last name.
Page 2 Record Layout
Sub Record_View()
Dim dtblTemp AS DataTable
Dim dvwRecord AS DataView
Dim RowIndex AS Integer
Dim numrows AS INTEGER
SESSION("PREV") = 0
SESSION("NEXT") = 0
SESSION("FIRST") = 0
SESSION("LAST") = 0
dtblTemp = Cache("CACHED_TABLE")
numrows = dtblTemp.Rows.Count-1
SESSION("FIRST") = dtblTemp.Rows(0).Item("EMP_ID")
SESSION("LAST") = dtblTemp.Rows(numrows).Item("EMP_ID"))
dvwRecord = dtblTemp.DefaultView()
dvwRecord.Sort = Session("LASTNAME")
RowIndex = dvwRecord.Find("EMP_ID"))
IF RowIndex <> -1 THEN
IF RowIndex > 0 THEN
SESSION("PREV") = dvwRecord(RowIndex-1).Row(EMP_ID"))
END IF
IF RowIndex <> dtblTemp.Rows.Count-1 THEN
SESSION("NEXT") = dvwRecord(RowIndex+1).Row("EMP_ID"))
END IF
END SUB