1

I have a formview in a ASP form that I use to edit and view information. The form contains a lot of dropdownlist controls and most of them aren't required fields. In the edit template I use ddlInfoEstStatus.Items.Insert(0, new ListItem("", "*")); to show an empty row.

The problem I am having is that using the code above doesn't work in the item template after binding the dropdownlist to the datasource.

Edgar J. Rodriguez
  • 285
  • 1
  • 2
  • 13
  • Could you provide some additional code snippets of the context in which this line of code appears? – Shai Aharoni Aug 12 '13 at 14:40
  • Are you possibly adding that item and then databinding? Because that will wipe out what you had in it before. – Kevin DeVoe Aug 12 '13 at 14:41
  • Are you binding first and then executing that line? If not, you need to bind the list first otherwise it'll be overwritten. http://stackoverflow.com/questions/267064/asp-net-add-blank-item-at-top-of-dropdownlist – Tanner Aug 12 '13 at 14:42

1 Answers1

2

You need to allow the databound items to be appended to your existing list items (including them empty ones) by setting AppendDataBoundItems to true on your DropdownLists.

<asp:DropDownList runat="server" ID="yourDDL"
    AppendDataBoundItems="true">
Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
  • Yep that solved the problem. We were using AppendDataBoundItems and also using the databinding in the item template, that caused the items to duplicate. Removing the binding made it work as we intended. – Edgar J. Rodriguez Aug 12 '13 at 15:11