Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET 2.0 Data Cache sort problem

Status
Not open for further replies.

WIREMESH

Programmer
Mar 15, 2004
109
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top