如何在中继器内设置 dropDownList 的选定项?
在后面的代码中,repeater绑定到repeaterData DataTable,dropDownList绑定到dropDownList DataTable。我需要将 DropDownList 的 SelectedValue 属性设置为 repeaterData 表中字段的值。
这是我尝试过的:
<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>
填充中继器的代码:
myRepeater.DataSource = myRepeaterData; //myRepeaterData is a datatable
myRepeater.DataBind();
填充下拉列表的代码:
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();
}
}