Keeping DropDownList from repeating databound items

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.
 
A

Andy B.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,811
Latest member
SaulFernan

Latest Threads

Top