Add empty item to dropdownlist of custom objects in C#

前端 未结 4 2027
生来不讨喜
生来不讨喜 2021-01-05 12:09

We are binding a list of custom objects to an ASP.NET DropDownList in C# but we want to allow for the DropDownList to not have anything selected initially. One way of doing

4条回答
  •  醉梦人生
    2021-01-05 12:26

    Yes, create your list like so:

    
        
    
    

    (Note the use of AppendDataBoundItems="True")

    And then when you bind, the bound items are put after the empty item rather than replacing it.

提交回复
热议问题