473,466 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP DataGrid Sorting

Hi all,

I have written a simple Web Application that displays a query result onto a
page using the ASP DataGrid.

To Digress
=======
Development information about the page is as follows
1. The database used is SqlServer 2000.
2. A Stored Procedure is dragged onto the page from the Server Explorer
creating a connection and command object.
3. An adapter object is dragged onto the page from the Toolbox and the
SelectCommand property is assigned the command object generated in step 2
4. A dataset object is created from the adapter object
5. In the page load, the relevent Adapter.Fill(dataset) and Grid.ReBind()
functions are called.

The above leads to a web page that displays the information retrieved by the
Stored Procedure.

The Problem
=========
I have attempted to add sorting to the Grid. I have selected what is
required to receive the Grid_SortCommand event in my page object and the
e.SortExpression is returning the name of the field selected but any
attempts to sort the data based on the SortExpression fails.
The line I am using to sort is
Dataset.Tables(0).DefaultView.Sort = e.SortExpression
This is run after the dataset has been filled by the adapter but before the
grid is rebinded to the dataset.

The Question(s)
===========
Can a grid be sorted when it is populated by a Stored Procedure? (cringe if
this is so)
Or; Have I failed to take something fundamental into account?

All the examples I have found work with dynamically created
dataviews/datatables.

Any help would be greatly appreciated.

Thanks in advance.

Mark
Nov 18 '05 #1
4 2337
Hi,

the sorting would generally happen in the datasource, DataGrid itself cannot
handle it on server automatically, that's why examples usually have
DataViews for sorting. Certainly you could sort, if you'd pass parameter to
the SP which indicates which sort order is used, but that might be bit
clumsy solution and needs lots of 'If' checking (unless you use dynamic SQL
in proc), of course this depends on what you are allowed to and can do.

This example uses the dynamic SQL and parameter passing technique:
http://www.dotnetjunkies.com/Article...0D57699C3.dcik

There are solutions which utilize the sorting on client-side, here is one:
http://www.eggheadcafe.com/articles/20021022b.asp

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Mark Travis" <mt*****@sysdel.skmconsulting.com> wrote in message
news:OA**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid.

To Digress
=======
Development information about the page is as follows
1. The database used is SqlServer 2000.
2. A Stored Procedure is dragged onto the page from the Server Explorer
creating a connection and command object.
3. An adapter object is dragged onto the page from the Toolbox and the
SelectCommand property is assigned the command object generated in step 2
4. A dataset object is created from the adapter object
5. In the page load, the relevent Adapter.Fill(dataset) and Grid.ReBind()
functions are called.

The above leads to a web page that displays the information retrieved by the Stored Procedure.

The Problem
=========
I have attempted to add sorting to the Grid. I have selected what is
required to receive the Grid_SortCommand event in my page object and the
e.SortExpression is returning the name of the field selected but any
attempts to sort the data based on the SortExpression fails.
The line I am using to sort is
Dataset.Tables(0).DefaultView.Sort = e.SortExpression
This is run after the dataset has been filled by the adapter but before the grid is rebinded to the dataset.

The Question(s)
===========
Can a grid be sorted when it is populated by a Stored Procedure? (cringe if this is so)
Or; Have I failed to take something fundamental into account?

All the examples I have found work with dynamically created
dataviews/datatables.

Any help would be greatly appreciated.

Thanks in advance.

Mark

Nov 18 '05 #2
Hi Mark,

I've notice that this issue is the same one with another one you post in
the public.dotnet.framework.adonet group. Teemu and I have also posted
replies in that one. I'd appreciate if you have a look there. In addition,
if you feel it convenient that we continue to discuss in that thread,
please feel free to followup there. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #3
I have a collection object bound to my grid and after the sort command is
raised I call my doDataBind method (which mnay other events also call). In
that method I sort my collection based on the value clicked and then make it
the data source for the grid and then call databind on the grid.
--
Joe Fallon


"Mark Travis" <mt*****@sysdel.skmconsulting.com> wrote in message
news:OA**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid.

To Digress
=======
Development information about the page is as follows
1. The database used is SqlServer 2000.
2. A Stored Procedure is dragged onto the page from the Server Explorer
creating a connection and command object.
3. An adapter object is dragged onto the page from the Toolbox and the
SelectCommand property is assigned the command object generated in step 2
4. A dataset object is created from the adapter object
5. In the page load, the relevent Adapter.Fill(dataset) and Grid.ReBind()
functions are called.

The above leads to a web page that displays the information retrieved by the Stored Procedure.

The Problem
=========
I have attempted to add sorting to the Grid. I have selected what is
required to receive the Grid_SortCommand event in my page object and the
e.SortExpression is returning the name of the field selected but any
attempts to sort the data based on the SortExpression fails.
The line I am using to sort is
Dataset.Tables(0).DefaultView.Sort = e.SortExpression
This is run after the dataset has been filled by the adapter but before the grid is rebinded to the dataset.

The Question(s)
===========
Can a grid be sorted when it is populated by a Stored Procedure? (cringe if this is so)
Or; Have I failed to take something fundamental into account?

All the examples I have found work with dynamically created
dataviews/datatables.

Any help would be greatly appreciated.

Thanks in advance.

Mark

Nov 18 '05 #4
Hi Teemu,

Thanks for the response. The first solution is my last resort. I had already
considered this but I thought I must be doing something wrong. It's had to
believe that Microsoft doesnt' support sorting a dataset based on Stored
Procedure. The second solution is very neat but unfortunately my data spans
pages.

As I said in my reply to Steven Cheng, I am either missing something very
simple or miss understanding the technology. All my knowledge is gained of
online documentation and the web. I think I will go out and hit a book shop
tonight.

Thanks again

Mark
"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:ef**************@TK2MSFTNGP10.phx.gbl...
Hi,

the sorting would generally happen in the datasource, DataGrid itself cannot handle it on server automatically, that's why examples usually have
DataViews for sorting. Certainly you could sort, if you'd pass parameter to the SP which indicates which sort order is used, but that might be bit
clumsy solution and needs lots of 'If' checking (unless you use dynamic SQL in proc), of course this depends on what you are allowed to and can do.

This example uses the dynamic SQL and parameter passing technique:
http://www.dotnetjunkies.com/Article...0D57699C3.dcik
There are solutions which utilize the sorting on client-side, here is one:
http://www.eggheadcafe.com/articles/20021022b.asp

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Mark Travis" <mt*****@sysdel.skmconsulting.com> wrote in message
news:OA**************@TK2MSFTNGP10.phx.gbl...
Hi all,

I have written a simple Web Application that displays a query result onto
a
page using the ASP DataGrid.

To Digress
=======
Development information about the page is as follows
1. The database used is SqlServer 2000.
2. A Stored Procedure is dragged onto the page from the Server Explorer
creating a connection and command object.
3. An adapter object is dragged onto the page from the Toolbox and the
SelectCommand property is assigned the command object generated in step

2 4. A dataset object is created from the adapter object
5. In the page load, the relevent Adapter.Fill(dataset) and Grid.ReBind() functions are called.

The above leads to a web page that displays the information retrieved by

the
Stored Procedure.

The Problem
=========
I have attempted to add sorting to the Grid. I have selected what is
required to receive the Grid_SortCommand event in my page object and the
e.SortExpression is returning the name of the field selected but any
attempts to sort the data based on the SortExpression fails.
The line I am using to sort is
Dataset.Tables(0).DefaultView.Sort = e.SortExpression
This is run after the dataset has been filled by the adapter but before

the
grid is rebinded to the dataset.

The Question(s)
===========
Can a grid be sorted when it is populated by a Stored Procedure? (cringe

if
this is so)
Or; Have I failed to take something fundamental into account?

All the examples I have found work with dynamically created
dataviews/datatables.

Any help would be greatly appreciated.

Thanks in advance.

Mark


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris Mayers | last post by:
I have a Windows Forms DataGrid that has a DataView as a datasource. My problem is that I want the datagrid to exhibit some special sorting properties when the header rows are clicked on. From...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
1
by: Sargas Atum | last post by:
Hi all, 1. I have a problem with cell selection in a table in a DataGrid. I dont want that anybody writes in the cells. That was not a problem I changed them to "read only", but if I am going...
3
by: melanieab | last post by:
Hi, I'm programatically sorting in a datagrid. When a column header is clicked, the sort happens twice for some reason, making it looks like it only sorts in descending order. I can tell it...
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...
4
by: Manny Chohan | last post by:
hi guys, my code is returning an array and i need to create datagrid so that i can have sorting and implement prev....next function on it to navigate. is there any way this can be done in...
5
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
1
by: ECD | last post by:
Hello all, I can usually find solutions to my .NET problems by searching these groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0 framework). I want to disable sorting on...
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.