Datagrid sort

G

Guest

Hello,
My question is about the datagrid sorting. I have a datatable that is filled
up with the data retrieved from an SQL query.I use that datatable as source
for my datagrid. I would like to make the datagrid sortable by each of the
columns but I don´t want to run the SQL query again. The problem is that I'm
loosing the datatable every time the sorting function is launched. I'm not
allowed to use session variables and I don't know how to store the datatable
in order that I don't loose it when the sorting is launched.
I would be very gratefull if you could post an example of how can I solve
this issue.
Thnaks a lot.
 
G

Guest

Thanks Rakesh.
I found other way to keep the datatable stored.
I have cached the resulting datatable and then retrieved it from cache,
this way I do not need to launch the SQL query again. the code was someting
like this:

SQLResults = SQLQuery.execute
'Cahe the resulting datatable.
Cache("DataTableCached") = SQLResults
BindGrid()

Sub BindGrid()
'Retrieve Datasource from Cache
Dim source As DataTable
source = Cache("DataTableCached")
'return a DataView to the DataTable
Dim dv As DataView = New DataView(source)
If SortField Is Nothing Then
SortField = "Title"
End If
dv.Sort = SortField
dg_Results.DataSource = dv
dg_Results.DataBind()
End Sub
 
B

Ben Lucas

Is the DataTable you use going to contain the same data for all of your
users? If so, then your solution is fine. If it should be different for
each user, then you may have a problem. What is stored in the cache is
accessible at a site-wide level, rather than at the request level.

Other alternatives for storage locations are:
Session
ViewState

Often, if the DataTable is relatively small in size and I need to provide
sorting capabilities, I place it in the ViewState to avoid doing another hit
to the database. Only drawback to this is that the larger the DataTable,
the more data must be sent down to the client for the ViewState.
 
G

Guest

Hi Ben, you are right. I tought that I could use several caches for each of
the different datatables for the results, but finnaly it wasn't possible. I
was thinking about the session variables, but I can't use them because we
have disabled the session variables in the sever for performance purposes.
I'm interested in the view state option you mentioned. How can I store a
datatable in the view state? What happens if the datatable is large (about
1000 rows)?
Thank you ben.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top