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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort by column

Status
Not open for further replies.

oxenberg

Programmer
Jul 1, 2002
28
US
I was wondering if it was possible to sort the rows in a report by column, similar to a listview control. I'd like to be able to click on a column header have the rows sort in ascending order by that column, then click again and have the rows sort in descending order by that column. If not, any suggestion on how to achieve this functionality?

I'm using the version of CR that comes with VS.Net and this will be in a web application.

Thanks
Phil
 
how did you do it? Howard Hammerman,

Crystal Reports training, consulting, books, training material, software, and support. Scheduled training in 8 cities.
howard@hammerman.com
800-783-2269
 
Probably not the best approach and I'd appreciate a better solution:

In the column header (label) of the report I added a hyperlink back to same page with a paramter to be used as a flag to tell my aspx code to sort and a second parameter to tell code what page of the report I am on.

Back in asp code I re-populate dataset as I always do in the OnInit handler. Then based on the parameter passed I know which column to sort on and I select this field to be sorted on like so:

Note: cr is a local varibale for my ReportClass object and "Total Redemptions" is my column label.

FieldDef = cr.Database.Tables [0].Fields ["Total Redemptions"];
cr.DataDefinition.SortFields [1].Field = FieldDef;
if (sortDirection == SortDirection.AscendingOrder)
cr.DataDefinition.SortFields [1].SortDirection = SortDirection.DescendingOrder;
else
cr.DataDefinition.SortFields [1].SortDirection = SortDirection.AscendingOrder;
where sortDirection is a static varoable containing previous sort value.

I suppose I could've sorted on the dataset itself, might this have been faster? It'd be nice if I could even use same dataset as first time w/o having to refresh from sql server. Suggestions would be appreciated.

CrystalReportViewer1.ReportSource = cr;
CrystalReportViewer1.RefreshReport();
CrystalReportViewer1.ShowNthPage(MainReport.nPageNumber); (yes, I also pass in the page number on the hyperlink and save it as a static in the ReportClass object)

Seems to work ok with a small data sample size. Haven't tested for scalability with lots of data.

What do you think?

Phil


 
Way cool. I'll test it tonight. Howard Hammerman,

Crystal Reports training, consulting, books, training material, software, and support. Scheduled training in 8 cities.
howard@hammerman.com
800-783-2269
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top