drop down list value in asp.net

前端 未结 9 2058
刺人心
刺人心 2021-01-18 08:29

I want to add a value to the drop down list that cannot be selected, like a title. Ex: I have a month drop down list. The very first item should be \"select month\" this sho

9条回答
  •  既然无缘
    2021-01-18 08:49

    These are ALL great answers if you want to work that hard. But my guess is that you already have the items you want for the list coming from a databound element, and only want to add to the top of that list the "Hey, dude - pick one!" option. Assuming that is the case...

    Here's the EASY Answer. And it ALWAYS works...

    1. Do your Databound List just like you planned.
    2. THEN, in Visual Studio, edit the items on dropdown,
    3. Add ONE MANUAL ITEM, make that your "Select an Item" choice,
    4. Using the properties window for the item in VS2012, check it as selected. Now close that window.
    5. Now, go to the properties box in Visual Studio on the lower left hand (make sure the dropdown is selected), and look for the property "AppendDataBoundItems".
    6. It will read False, set this to True.

    Now you will get a Drop Down with all of your data items in it, PRECEDED BY your "Select an Item" statement made in the manual item. Try giving it a default value if possible, this will eliminate any errors you may encounter. The default is Zero, so if zero is not a problem, then leave it alone, if zero IS a problem, replace the default zero in the item with something that will NOT crash your code.

    And stop working so hard...that's what Visual Studio is for.

提交回复
热议问题