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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Databound dropdown ASP.net

  • 07-08-2007 11:02pm
    #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: 41,240 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, 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,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