【发布时间】:2012-03-13 15:41:50
【问题描述】:
我在具有预定义项的 ASP.NET 页面中的转发器控件内有一个 DropDownList。将数据绑定到转发器控件后,我将如何设置它的选定值?
例如,我有这样的代码:
<asp:DropDownList ID="cboType" runat="server">
<asp:ListItem Text="Communication" Value="Communcation" />
<asp:ListItem Text="Interpersonal" Value="Interpersonal" />
</asp:DropDownList>
因为 DropDownList 控件没有 SelectedValue 前端属性,所以无法在控件级别进行设置。相反,您必须使用 列表项 的 selected 属性。理想的情况是:
<asp:DropDownList ID="cboType" runat="server" SelectedValue='<%# Eval("Type_Of_Behavior") %>'>
<asp:ListItem Text="Communication" Value="Communcation" />
<asp:ListItem Text="Interpersonal" Value="Interpersonal" />
</asp:DropDownList>
很遗憾,这行不通,有什么想法吗?
【问题讨论】: