У меня есть формвью, дропдаун в котором надо заполнить программно. В каком обработчике это сделать? У меня вываливается либо 'GenreList' has a SelectedValue which is invalid because it does not exist in the list of items. либо 'Bind, Eval can only be used in databound control'
код:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="FormsBench.Edit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script runat="server">
protected Dictionary<string, string> Genres = new Dictionary<string, string>(){{"fiction", "fiction"}};
</script>
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<asp:formview id="FormView1" runat="server" datakeynames="Id" defaultmode="Edit" datasourceid="EntityDataSource1">
<edititemtemplate>
Id: <asp:label id="IdLabel1" runat="server" text='<%# Eval("Id") %>' />
Title: <asp:textbox id="TitleTextBox" runat="server" text='<%# Bind("Title") %>' />
AuthorId: <asp:textbox id="AuthorIdTextBox" runat="server" text='<%# Bind("AuthorId") %>' />
Genre: <asp:dropdownlist id="GenreList" runat="server" selectedvalue='<%# Bind("Genre") %>' />
<asp:linkbutton id="UpdateButton" runat="server" causesvalidation="True"
commandname="Update" text="Update" />
<asp:linkbutton id="UpdateCancelButton" runat="server"
causesvalidation="False" commandname="Cancel" text="Cancel" />
</edititemtemplate>
</asp:formview>
<asp:entitydatasource id="EntityDataSource1" runat="server"
connectionstring="name=SandBoxEntities" defaultcontainername="SandBoxEntities"
enableflattening="False" enableupdate="True" entitysetname="Books"
entitytypefilter="Book">
</asp:entitydatasource>
</form>
</body>
</html>