473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

order by drop down list

229 100+
Hi I wonder if anyone could point me in the right direction. I order the data on my page by the date added asc. I would like the user to be able to order the results from a drop down list like

order by date
order by name asc
order by category

etc.....
Any ideas how this is done would be great.
Thanks
Richard
Jun 4 '09 #1
3 3058
GazMathias
228 Expert 128KB
Hi,

I would use JavaScript to send the value of the drop down onChange.

Expand|Select|Wrap|Line Numbers
  1. function orderby() {
  2.  
  3.   var selObj = document.getElementById("cbo_OrderBy");
  4.   var order_by = selObj.options[selObj.selectedIndex].value;
  5.  
  6.   location.href = "somepage.asp&orderby=" + order_by;
  7.  
  8. }
  9.  
  10.  
  11. <select id = "cbo_OrderBy" onChange="orderby();">
  12. <option value="date">order by date</option>
  13. <option value="name">order by name</option>
  14. <option value="category">order by category</option>
  15. </select>
  16.  
Obviously "somepage.asp" would be the same page.

It would then just be a matter of modifying the SQL statement to use the value passed in the Query String.

Gaz.
Jun 5 '09 #2
fran7
229 100+
Thanks Gaz, just what i wanted and got it working fine.
Thanks
Richard
Jun 5 '09 #3
GazMathias
228 Expert 128KB
No problem,

For anyone else using this code in the future, notice the typo in the JavaScript :

Expand|Select|Wrap|Line Numbers
  1. somepage.asp&orderby=" + order_by;
  2.  
Should be:

Expand|Select|Wrap|Line Numbers
  1. somepage.asp?orderby=" + order_by;
  2.  
It was before me first coffee of the day!
Jun 5 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
2
by: Irishmaninusa | last post by:
Hello Everyone, I am populating a dropdown control from a database where the data is datetime values. In my stored procedure I am ordering them by where the most recent is at the top and the...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
1
by: Richard Myers | last post by:
Hello I have a problem in that my dhtml/css drop down menu layers will not, no matter what z-order setting i choose, display over top of a asp.net webcontrol drop down list. I ve Googled up...
3
by: beconrad | last post by:
Hi all, I am not sure if what I want to do is possible, and if it is I have not been able to figure out how to do it. This is what I would like: 1. I have a data entry form with a field...
5
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.