How do I set the selected item of a dropDownList inside a repeater?
The repeater is bound to the repeaterData DataTable and the dropDownList is bound to dropDownList DataTable in the code behind. I need to set the SelectedValue property of the DropDownList to the value of a field from the repeaterData table.
This is what I've tried:
<asp:Repeater runat="server" ID="myRepeater>
<ItemTemplate>
<asp:DropDownList runat="server" CssClass="fullSelect" ID="degree_dropdown"
AppendDataBoundItems="true"
selectedValue='<%#DataBinder.Eval(Container.DataItem,"degreeCode")%>'>
<asp:ListItem Text="Select Degree" />
</asp:DropDownList>
</ItemTemplate>
</asp:Repeater>
Code to populate repeater:
myRepeater.DataSource = myRepeaterData; //myRepeaterData is a datatable
myRepeater.DataBind();
Code to populate dropdownlist:
protected void educationPopup_repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DropDownList degree_dropdown = e.Item.FindControl("degree_dropdown") as DropDownList;
if (degree_dropdown != null)
{
degree_dropdown.DataSource = degrees; //a datatable
degree_dropdown.DataTextField = "degree";
degree_dropdown.DataValueField = "code";
degree_dropdown.DataBind();
}
}
degree_dropdown
with data? Could you post the code? – Empathy