Page 1 of 1

Changing sort during runtime

Posted: Mon May 21, 2007 5:44 pm
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.

Changing sort during runtime

Posted: Wed May 23, 2007 2:35 am
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.

Changing sort during runtime

Posted: Tue Mar 03, 2009 11:26 pm
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.

Changing sort during runtime

Posted: Wed Mar 04, 2009 2:42 am
by Jan
Hello,

Please use following code:

Code: Select all

DataBand1.Sort = new string[4]
{
"ASC",
"Name",
"ASC",
"Alias"
};
Thank you.

Changing sort during runtime

Posted: Sun Mar 08, 2009 7:55 pm
by ptabkra
Yup. Thanks jan, that works fine.

Changing sort during runtime

Posted: Mon Mar 09, 2009 10:03 am
by Edward
Please let us know if any additional help is required.

Thank you.

Re: Changing sort during runtime

Posted: Thu May 10, 2018 12:58 am
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

Re: Changing sort during runtime

Posted: Fri May 11, 2018 7:09 pm
by HighAley
Hello, Soni.

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

Thank you.

Re: Changing sort during runtime

Posted: Fri Aug 20, 2021 11:01 am
by Kiyaksar
Where should we write the code:
DataBand1.Sort = new string[2]
{
"ASC",
"Name"
};

Re: Changing sort during runtime

Posted: Fri Aug 20, 2021 9:15 pm
by Lech Kulikowski
Hello,

As a way, in the BeforePrint event.

Thank you.