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

Sort Records on ASP page from access database

Status
Not open for further replies.

soldierB

Technical User
Dec 11, 2005
37
0
0
GB
Hi Guys,

I have a page that loads up a recordset from my database and displays them in order of the Date field.

But being on other sites I see sorting options on the page that allows the list to be sorted by Name or Price etc and it appears to be running from the same page.

Can anyone advise me on how to add this to my list so my users can choose how to sort.

What I have is a basic recordset created by DW and the sort is set to date. Then a repeat region to loop through and get all the records.

I did think I could just make up a few other pages all set to sort the recordset differently and it would look like the same page, but is there a better way?

Any help is appreciated.

Thanks again
 
u would assign an action to button/dropdown etc. in the form then have 'onChange' submit this form and re-sort recordset on the same page..no need for multiple pages..
All the best!

:--------------------------------------:
fugitive.gif

[URL unfurl="true"]http://mostarnet.com[/url]

All around in my home town,
They tryin' to track me down...
 
Thanks lebisol,

So at the moment Dreamweaver created my recordset, do I still use this recordset to re sort or am I making a new recordset to sort by?

The buttons or list box I use to assign the action would these need to be in my pages main form at the moment? or do I add a new form for them on their own?

Sorry to ask so many dumb questions..

Also can you give me an example of the action I would assign to the button.

Thanks again
 
you would use the same recordset....if you remember you are give an option to 'sort by' in DW when creating a recordset ..
My suggestion would be to build (on initial 'search page' or a 'form page') this option...such as a drop down box that will contain
sort by:[ Price,Item Name etc.]
in order of: [ A-Z, Z-A]

and leave them at some default so it will sort a recordset...
then, on the 'results' page offer results with a form that wil submit itslef to the same page...in essencse your form is inculded on the results page and you can use the same recordset to re-sort it.
Sorry I dont have devpc handy to give a samle code but perhaps this weekend I can help out if you are still stuck.
This will require some hand coding as DW doesnt have it builtin their behaviors...the 'action' on the drop-down form would be a simple JavaScript
<select name="some" onchange="this.form.submit();">

All the best!

:--------------------------------------:
fugitive.gif

[URL unfurl="true"]http://mostarnet.com[/url]

All around in my home town,
They tryin' to track me down...
 
Thanks,
I will have a think over what you have said and see what I can understand there. I do not know any JS so will need some guidance there if possible....

I only have 1 page at the moment and it just lists the recordset very simple page.

So im thinking I can do all this on 1 page and just use the form submit to reload the page again with the new recordset sort parimiter?

I would appreciate a little more help if you have the time and will watch out for this thread.

Thanks again.
 
Hi Lebisol

I think I have done it thanks to your guidance. Im not sure how clever my coding is but its running!!

I have a couple of questions if anyone can advise me further on this.

This is what Ive done

I made a few new session Vars and set their values to the strings that my connection string used in the sort

EG: Used to read like this
Code:
'Recordset1.Source = "SELECT * FROM shows1 ORDER BY showdate DESC"

Now reads:

Code:
Recordset1.Source = "SELECT * FROM shows1 ORDER BY " & Session("SortOpen")

Session("SortOpen") is set to take the value of the drop down lists choice, if there has been no choice made like when the page first loads it takes a default value I have set.

Code:
Session("SortOpen")=request.Form("selectsort")
if Session("SortOpen")="" then
Session("SortOpen")="date DESC"
end if

So as I say this seems to be working and Dreamweaver hasnt thrown any errors in the recordset with me editing the sort string........

But what I now need to finish it I think is to anchor the page after the sort is selected.

The section the sort list box is at is roughly half way down the page so when the forms submited to do a new sort the page reloads at the top again and the user has to scroll down to get back to the table of resorted data.......

How do i throw an anchor point into the mix here, I tried adding #list into the forms submit action but its not working!!

Thanks again for any advice.

 
excellent!
Don't bother with the anchors....consider using 2 drop downs on the same page..top and bottom
eg.
---------form------------
sort by:[___]

1.results...
2....
3...
4. results...

sort by:[___]
-------------form---------


All the best!

:--------------------------------------:
fugitive.gif

[URL unfurl="true"]http://mostarnet.com[/url]

All around in my home town,
They tryin' to track me down...
 
hi soliderb,
one more thing is to stay away from sessions variables but rather use a Request.Form elements throughout. Sessions are additional burden on the server side that in this case in not really neccessary...
All the best!

:--------------------------------------:
fugitive.gif

[URL unfurl="true"]http://mostarnet.com[/url]

All around in my home town,
They tryin' to track me down...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top