locked
drop down list RRS feed

  • Question

  • Hi

    I have a drop down list which gets populated from database but I want to add the default value as

    --Select----

    Friday, January 19, 2007 4:41 PM

Answers

  • Your string should look like this:

    "select '--Choose One--' as typeName union select typeName from attributeType"

    Remember to check for the default value before saving your information. You don't want to save "Choose One" to your database.

    Friday, January 19, 2007 5:49 PM

All replies

  • Here's a trick you can use. Use a Union query to append your default to your database results, like so:

    SELECT 
       
    0
    as EmployeeID,
       
    '-- Select An Employee --' as EmployeeName

    UNION

    SELECT 
       
    EmployeeID,
       
    FirstName + ' ' + LastName as EmployeeName
    FROM
       
    employees

    Friday, January 19, 2007 4:58 PM
  •  

    Hi Frank

    I tried it but I think I am not putting the qoutes properly.

    SqlCommand("select '"&--Choose One--&"'" as typeName union select typeName from attributeType")

    Friday, January 19, 2007 5:12 PM
  • Your string should look like this:

    "select '--Choose One--' as typeName union select typeName from attributeType"

    Remember to check for the default value before saving your information. You don't want to save "Choose One" to your database.

    Friday, January 19, 2007 5:49 PM
  •  

     

    Thanks Frank!!!

    I tried t his also, creating a view on the table and than selecting the data from view.It works fine but I don't think its a good method.

    Friday, January 19, 2007 6:13 PM