简体   繁体   中英

how to display the items in the combobox in any given manner?

I have a dropdown getting populated by fetching a query on the database. Say it fetches items given as follows:

Teacher, Student, Pricipal, Sweeper, FinanceManager.

While showing it in the dropdown, I wish to show it in the following order:

Principal, FinanceManager, Teacher, Student, Sweeper.

This isn't any specific order (ascending or descending), but just a order that has some relevance according to the personalities.

How do I acheive?

Since you fetching the data from database,the easy solution to me is adding a extra column to the same table which hold order.

eg. Your Table
    Column1 Column2 .... DisplayOrder(int)
    Principal                     1
    FinanceManager                2
    etc...

So you can order by the DisplayOrder when you do the selection

you could give them an extra "role-flag" in your db

ID NAME       FLAG
1  Principal  5
3  FinanceM   4
33 Teacher    3
22 Student    2
99 Sweeper    1

and you could do the query by "order by FLAG"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM