views:

23

answers:

1

I'm using entity framework and i have a problem that this dropdown ignores my changes / does not reflect db.

 <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' (in binding) is an int and it's 1. When the form is started, I always see NO, although the value coming from EF is 1. What is wrong please?

A: 

Use the 'SelectedValue' property instead of DataValueField. DataValueField is used to specify the property in the datasource to bound for the ListItem value.

<asp:DropDownList ID="myDD" runat="server" AppendDataBoundItems="true"   SelectedValue='<%# Bind("something") %>'>            
alejandrobog