By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,704 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,704 IT Pros & Developers. It's quick & easy.

Datagrid sort

P: n/a
ETX
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.
Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi ETX,

Check out these articles which discuss the same:
http://msdn.microsoft.com/msdnmag/is...e/default.aspx
http://www.eggheadcafe.com/articles/20021022b.asp

HTH,
Rakesh Rajan

"ETX" wrote:
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.

Nov 22 '05 #2

P: n/a
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.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"ETX" <ET*@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
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

"Rakesh Rajan" wrote:
Hi ETX,

Check out these articles which discuss the same:
http://msdn.microsoft.com/msdnmag/is...e/default.aspx
http://www.eggheadcafe.com/articles/20021022b.asp

HTH,
Rakesh Rajan

"ETX" wrote:
> 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 dont 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.

Nov 22 '05 #3

P: n/a
ETX
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.

"Ben Lucas" wrote:
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.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

"ETX" <ET*@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
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

"Rakesh Rajan" wrote:
Hi ETX,

Check out these articles which discuss the same:
http://msdn.microsoft.com/msdnmag/is...e/default.aspx
http://www.eggheadcafe.com/articles/20021022b.asp

HTH,
Rakesh Rajan

"ETX" wrote:

> 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.


Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.