Keeping DropDownList from repeating databound items

  • Thread starter Thread starter Andy B.
  • Start date Start date
A

Andy B.

I have a databound DropDownList in the HeaderTemplate of a DataList. When I
run the page, the databound items appear twice in the DropDownList. I get my
data from an entity framework link back to a database. So, instead of having
these items: View all years, 2009, 2004 I have this: View all years, 2009,
2004, 2009, 2004. Any idea how to fix this? Just a note that whenever I
remove the DropDownList from the headerTemplate and put the
datasource/databind for the DropDownList in an if not IsPostBack block
everything works fine.
 
Ok. Figured it out with your pointer there. I had the code to databind the
DropDownList in the ItemCreated event of the DataList. Didn't think that the
controls haven't been databound by that time yet. So my extra call to
DropDownList.DataBind() created the second set of items.
 
Back
Top