I've searched and I can't find an answer to my problem. I'm new to ASP .Net Repeaters, and I'm finding this confusing.
I created a repeater and it is bound to a datasource that selects certains rows from a database. The repeater contains several controls including a drop down list. This list is populated at databinding as I need it to contain specific values, but also start with the correct selected index based on the value currently stored in the database. Basically, I pull in a graduating year for a list of students, and the drop down list has the possible levels - senior, junior, sophomore, etc. Based on the graduating year in the database, the drop down list should display the corresponding level which could then be corrected by the user. When I populate the controls in the repeater (including the DropDownList) using a function handling myRepeater.ItemDataBound, everything displays correctly, except the DDL populates with duplicate values. What I mean is, the student name displays correctly, but within the DDL, the levels are displayed twice each - it shows Senior, Junior, Sophomore, ... and then Senior, Junior, Sophomore, ... again.
The only workaround I came up with was to wait for the list to populate and then remove the last half of the DDL items based on the DDL.items.count. It works, although I don't know why I am getting duplicates in the first place.
I could live with that, but now when I try to read the controls upon the click of a button, everything is duplicated. When I do a "FOR EACH item in myRepeater.Items" loop, I can find all of the controls using findcontrol. To troubleshoot, I spit out the output values so I could read what would go back to the database. Everything is duplicated. It reads each item, writes out the values for each control in the itemtemplate, then duplicates again. So, it shows the values (name, level, etc.) for student 1, student 2, student 3, ... and then repeats student 1, student 2, student 3, ...
I am at a loss as to what could be causing this issue. The repeater template displays the information properly, but the controls seem to be duplicating when I get their values. I don't know if it is something that occurs at databinding, or on page postback, or what. But on the page I see "John Doe" and the DDL has "senior" selected, and the next row has "Jane Doe" and "junior". I submit the page, and the output values are:
"John Doe", "senior"
"Jane Doe", "senior"
"John Doe", "senior"
"Jane Doe", "senior"
They only show up once in the repeater control, but the output duplicates. It would be great if anyone could point me in the right direction to address this problem. Part of the problem is that since items can also be added and not just updated, I can't afford to have duplicates inserted into the database. Duplicate update statements wouldn't kill me, even though it's stupid to send the same update twice, but duplicate insertions are a problem.
Thanks in advance