473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Datagrid sort

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
3 2310
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
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 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the...
0
by: Robert Brinson | last post by:
Hello all! I'm running .NET Framework 1.1 using VS.NET 2003. I've got a mystery with a DataGrid. Below is the definition of the DataGrid from my aspx page: </asp:datagrid><asp:datagrid...
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
2
by: shuckjunkmail | last post by:
It was suggested that I re-submit this question as a new post rather than adding onto an old and unanswered post. The basic problem has to do with the .NET datagrid and sorting. I am having...
2
by: Joey | last post by:
I have an asp.net 1.1 C# web application with a datagrid. I set the datagrid's "AllowSorting" property to "True". Then I created a sort function for it by selecting the datagrid in the designer,...
0
by: rn5a | last post by:
A DataGrid control displays records from a SQL Server 2005 DB table. The AllowSorting property of the DataGrid has been set to True & the SortExpressions of the BoundColumns have been set to the...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.