我正在使用实体框架,我有一个问题,这个下拉列表忽略了我的更改/不反映数据库。
<asp:FormView ID="FormView1" runat="server" DataSourceID="edsFoo" >
<asp:DropDownList ID="myDD" runat="server" AppendDataBoundItems="true" DataValueField='<%# Bind("something") %>'>
<asp:ListItem Value="0" Text="NO" />
<asp:ListItem Value="1" Text="YES" />
<asp:ListItem Value="2" Text="PARTIALLY" />
</asp:DropDownList>
</asp:FormView>
'Something'(在绑定中)是一个int,它是1。 当窗体启动时,我总是看到NO,尽管来自EF的值是1。 有什么不对吗?
答案 0 :(得分:0)
使用'SelectedValue'属性而不是DataValueField。 DataValueField用于指定数据源中要绑定ListItem值的属性。
<asp:DropDownList ID="myDD" runat="server" AppendDataBoundItems="true" SelectedValue='<%# Bind("something") %>'>