Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Databound dropdown ASP.net

  • 08-08-2007 12:02AM
    #1
    Closed Accounts Posts: 18,053 ✭✭✭✭


    I'm new to VB.net/ASP. I'm using a Databound dropdown in ASP.net (VB). The dropdown list is order in no sequence that I can fathom. How can I order it and and set the default. or better set the default as nothing so the user has to select something.


Comments

  • Moderators, Politics Moderators, Paid Member Posts: 44,040 Mod ✭✭✭✭Seth Brundle


    You are basing it on a query so presumably your query is something like
    SELECT DISTINCT [field1], [field2],field3] FROM [table]
    
    to sort it change it to:
    SELECT DISTINCT [field1], [field2],field3] FROM [table] ORDER BY [field2] ASC
    
    To had a blank default value and assuming there are no blanks in your table:
    SELECT DISTINCT [field1], [field2],field3] FROM [table] 
    UNION
    SELECT DISTINCT "","","" FROM [table] ORDER BY ORDER BY [field2] ASC
    


  • Closed Accounts Posts: 18,053 ✭✭✭✭BostonB


    I'll try that 2morrow ta.


  • Registered Users, Registered Users 2 Posts: 604 ✭✭✭Kai


    You can also add a default like this
    DropDownList ddl = new DropDownList();
    DataView dv = GetSomeData();
    ddl.DataSource = dv;
    ddl.DataTextField = "field1";
    ddl.DataValueField = "field2";
    ddl.DataBind();
    ddl.Items.Insert(0, new ListItem("Please select an option", "0"));  
    

    which may be an easier or more difficult option depending on how your doing it.


  • Closed Accounts Posts: 18,053 ✭✭✭✭BostonB


    Its actually not my code, just something that got passed to me. Found an error in the SQL and its sorted now. Cheers.


Advertisement