Showing posts with label listbox1. Show all posts
Showing posts with label listbox1. Show all posts

Sunday, March 11, 2012

Can sqldatasource automatically sort retrieved data from stored procedure ?

Hi,

This is my problem :

I have listBox1, listBox2 controls bound to sqldatasource1 and sqldatasource2.

I wrote one stored procedure to retrieve data from my sql database like :

select Id, Name,Address,Amount from KalakaDB

Now I want my listBox1 to display Name By name and my listBox2 to display Amount by decrease order

how can i connect my sqldatacontrol to the stored procedure ?

Thanks

Typically sorting is controlled by the data bound control (for example, the GridView). However, the sorting is actually performed by the data source. In this case if you don't have a way to tell the data bound control which sort express to use, you can do it directly on the data source by handling SqlDataSource's Selecting event. In that event, simply say something like:

e.Arguments.SortExpression = "Amount DESC";

Thanks,

Eilon