Add empty item to dropdownlist of custom objects in C#

前端 未结 4 2069
生来不讨喜
生来不讨喜 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:23

    First:

    DropDownList1.Items.Clear();

    Then add listItems to the dropDownList.

    This prevents the dropDownList from acquiring an ever increasing list of items every time it is rendered in a postback or asynchronous postback.

提交回复
热议问题