Databound drop down list - initial value

后端 未结 8 1882
小蘑菇
小蘑菇 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:58

    What I do is set the text property of the drop down list AFTER I databind it. Something like this:

       protected void LoadPersonComboBox()
        {
            var p = new PeopleBLL();
    
            rcmbboxEditPerson.DataSource = p.GetPeople();
            rcmbboxEditPerson.DataBind();
            rcmbboxEditPerson.Text = "Please select an existing person to edit...";
        }
    

    This makes the initial visible value of this dropdown show up, but not actually be a part of the drop down, nor is it a selectable.

提交回复
热议问题