Changing sort during runtime

Stimulsoft Reports.NET discussion
Post Reply
jamesk
Posts: 23
Joined: Thu Apr 12, 2007 12:47 pm

Changing sort during runtime

Post by jamesk »

I have a question regarding changing the sort during runtime.

I found a thread where someone suggested using the following:

Code: Select all

To change sorting see below:

DataBand1.Sort = new string[2]
{
"ASC",
"Name"
}; 
I have tried this and am unable to make this work. Is there something that I am missing?
Here is a toned down version of my code block for simplicity sake:

Code: Select all

Stimulsoft.Report.StiReport rptPreview;
Stimulsoft.Report.Components.StiDataBand bndPreview;
Stimulsoft.Report.Dictionary.StiSqlSource tsPreview;

rptPreview = LoadReport(_reportID);
bndPreview = MasterDatabandGet(rptPreview); //Retreives the Master databand for the loaded report

bndPreview.Sort = new string[2]
{
	"DESC"
	,"WorkOrderNumber"
};

tsPreview = rptPreview.DataSources[bndPreview.DataSource.Name] as Stimulsoft.Report.Dictionary.StiSqlSource;

// Need to pass WHERE and ORDER BY Clause
BuildWhereClause(ref tsPreview);
//SortBuild(ref tsPreview);

frmReportViewer frmX = new frmReportViewer();
frmX.MdiParent = this.MdiParent;

frmX.View(rptPreview, _reportID);
break;
	
The SortBuild function builds an ORDER BY clause that I have tried to alter the SQLCommand, but adding an ORDER BY clause doesn't alter the appearance of the data. It is possible that I am doing something incorrect, but have been unable to determine what it could be. The BuildWhereClause function is working correctly and curiously it is performing a similar action as the SortBuild. I have commented out the SortBuild function until I am able to get something to work.

Code: Select all

tsPreview.SqlCommand += " WHERE column = value "

tsPreview.SqlCommand += " ORDER BY column ASC"
I have no preference as to how to get the sort ability to work, whether I alter the SQLCommand or whether I use the built-in Sort of the StiDataBand.
I noticed that I instantiate bndPreview, then change the Sort, then use the name to reference which DataSource to use for tsPreview. But no where do I add it to the report itself. What am I missing here? Please help. Thanks.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Changing sort during runtime

Post by Edward »

Please do sorting of the DataBand in the BeginRender event of the Page. Due to sorting is performing via the DataBand, you do not need change sorting of the StiSqlSource or any other DataSource.

Thank you.
ptabkra
Posts: 27
Joined: Tue Oct 16, 2007 10:33 pm

Changing sort during runtime

Post by ptabkra »

Hi!
I've tried this code:

Code: Select all

DataBand1.Sort = new string[2]
{
"ASC",
"Name"
};
it works ok if i only need to sort by 1 column, but pls just correct me.
i need to sort by 3 or more columnds dynamically, pls advise how it could be possible? i tried to just add other columns but it isn't my desired result.

Thank you.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Changing sort during runtime

Post by Jan »

Hello,

Please use following code:

Code: Select all

DataBand1.Sort = new string[4]
{
"ASC",
"Name",
"ASC",
"Alias"
};
Thank you.
ptabkra
Posts: 27
Joined: Tue Oct 16, 2007 10:33 pm

Changing sort during runtime

Post by ptabkra »

Yup. Thanks jan, that works fine.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Changing sort during runtime

Post by Edward »

Please let us know if any additional help is required.

Thank you.
Soni.Garg
Posts: 1
Joined: Thu May 10, 2018 12:38 am

Re: Changing sort during runtime

Post by Soni.Garg »

hi

I have a similar issue where I want to sort a databand in the begin render event of the report. The databand needs to be sorted based on only one column (Net_Profit_Margin) but I am not sure of the exact syntax I need to use.


Any help will be great!!

Thanks
Soni
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Changing sort during runtime

Post by HighAley »

Hello, Soni.

Did you try to use the same code an above?
Did you get any issue?

Thank you.
Kiyaksar
Posts: 6
Joined: Sat May 01, 2021 5:53 pm

Re: Changing sort during runtime

Post by Kiyaksar »

Where should we write the code:
DataBand1.Sort = new string[2]
{
"ASC",
"Name"
};
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Changing sort during runtime

Post by Lech Kulikowski »

Hello,

As a way, in the BeforePrint event.

Thank you.
Post Reply