Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Databound dropdown ASP.net

Options
  • 08-08-2007 12:02am
    #1
    Closed Accounts Posts: 18,056 ✭✭✭✭


    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 Posts: 38,913 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,056 ✭✭✭✭BostonB


    I'll try that 2morrow ta.


  • Registered Users 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,056 ✭✭✭✭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