Databound drop down list - initial value

后端 未结 8 1898
小蘑菇
小蘑菇 2020-12-24 03:21

How do I set the initial value of a databound drop down list in ASP.NET?

For instance, I want the values, but the first value to display should be -- Select One ---

8条回答
  •  误落风尘
    2020-12-24 03:49

    I think what you want to do is this:

    
           
    
    

    Make sure the 'AppendDataBoundItems' is set to true or else you will clear the '--Select One--' list item when you bind your data.

    If you have the 'AutoPostBack' property of the drop down list set to true you will have to also set the 'CausesValidation' property to true then use a 'RequiredFieldValidator' to make sure the '--Select One--' option doesn't cause a postback.

    
    

提交回复
热议问题