I have a FormView which contains 5 dynamic DropDownLists. By dynamic, I mean the lists of dropdowns can be increased or decreased - depending on how many questions I have in my DB.
When I click the save button, I'm able to retrieve and store the content of the text boxes. But I'm not able to retrieve the DropDownLists.
One of the problems is that the ID of the DropDownLists changes name after I click the Save Button.
Why? Because upon Databinding of my DropDownLists, I rename the ID's so that I can identify which is which and store the appropriate data in the DB.
I'm not sure if I'm "attacking" this all wrong.
Here's my aspx code:
<asp:FormView runat="server" (...)>
//Lots of textfields here
<asp:Repeater runat="server" id="myRepeater"> //Datasource is bound in codebehind.
<ItemTemplate>
<li>
<div class="value"> <asp:DropDownList id="score" runat="server" OnDataBinding="hotelCriterias_DataBinding" /> </div>
</li>
</ItemTemplate>
</asp:Repeater>
</asp:FormView>
Here I rename the ID's and databind the datasource
protected void myDropDownList_DataBinding(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)(sender);
ddl.ID = "question" + Eval("questionID").ToString(); //Rename ID to 'question1, question2...)
Repeater rep = (Repeater)myFormView.FindControl("myRepeater");
rep.DataSource = this.dtQuestions;
rep.DataBind();
}