title: ASP.net listview dropdown item getting the value from another table
body: <p>I am trying to build an admin page in order to let the user create edit update the records of the specific table. "District" table has the following properties: DistrictID, DistrictName, Description, DistrictImage, CityFK. Since CityFK is just numbers which represents CityID of the table "City" and does not mean anything to the user I have used a dropdown menu instead and it displays all city names as "DataTextField" and CityIDs as "DataValueField" from the table "City". But my aim is to insert that "DataValueField" into the District table as CityFK. But whenever I enter a new District record and choose a City from the dropdown and press "Insert" button of the listview, CityFK of that regarding record is "0".</p>
  
  <p>I paste the whole listview but if you look at the dropdownlist at the InsertItemTemplate or EditItemTemplate you will what I mean;</p>
  
  <pre><code> &lt;asp:ListView ID="DistrictList" runat="server" DataKeyNames="DistrictID" InsertItemPosition="LastItem" DataSourceID="DistrictEntityDataSource" &gt;
      &lt;AlternatingItemTemplate&gt;
          &lt;tr style="background-color:#FFF8DC;"&gt;
              &lt;td&gt;
                  &lt;asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /&gt;
                  &lt;asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DistrictIDLabel" runat="server" Text='&lt;%# Eval("DistrictID") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DistrictNameLabel" runat="server" Text='&lt;%# Eval("DistrictName") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DescriptionLabel" runat="server" Text='&lt;%# Eval("Description") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Image ID="DistrictImageLabel" runat="server" Height="100px" ImageUrl='&lt;%# "~/Handlers/ImageHandler.ashx?ID="+Eval("DistrictID")+"&amp;Entity=District"%&gt;'/&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="CityFKLabel" runat="server" Text='&lt;%# Eval("CityFK") %&gt;' /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/AlternatingItemTemplate&gt;
      &lt;EditItemTemplate&gt;
          &lt;tr style="background-color:#008A8C;color: #FFFFFF;"&gt;
              &lt;td&gt;
                  &lt;asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" /&gt;
                  &lt;asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DistrictIDLabel1" runat="server" Text='&lt;%# Eval("DistrictID") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:TextBox ID="DistrictNameTextBox" runat="server" Text='&lt;%# Bind("DistrictName") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:TextBox ID="DescriptionTextBox" runat="server" Text='&lt;%# Bind("Description") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:FileUpload ID="FileUploadDistrict2" runat="server" /&gt;
  
              &lt;/td&gt;
               &lt;td&gt;
                  &lt;asp:DropDownList ID="CityFKDropDownList" runat="server" AutoPostBack="true" DataSourceID="ddlCityFK_DataSource" ViewStateMode="Enabled"
                      DataTextField="CityName" DataValueField="CityID"
                      AppendDataBoundItems="true"&gt;
                      &lt;asp:ListItem Text="-Stadt Wählen-" Value="0" &gt;&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
  
                  &lt;asp:EntityDataSource ID="ddlCityFK_DataSource" runat="server"
                      ConnectionString="name=MedicalEntities" DefaultContainerName="MedicalEntities"
                      EntitySetName="Cities" &gt;
                  &lt;/asp:EntityDataSource&gt; 
              &lt;/td&gt;
  
          &lt;/tr&gt;
      &lt;/EditItemTemplate&gt;
      &lt;EmptyDataTemplate&gt;
          &lt;table runat="server" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;"&gt;
              &lt;tr&gt;
                  &lt;td&gt;No data was returned.&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/EmptyDataTemplate&gt;
      &lt;InsertItemTemplate&gt;
          &lt;tr style=""&gt;
              &lt;td&gt;
                  &lt;asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /&gt;
                  &lt;asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:TextBox ID="DistrictIDTextBox" runat="server" Text='&lt;%# Bind("DistrictID") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:TextBox ID="DistrictNameTextBox" runat="server" Text='&lt;%# Bind("DistrictName") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:TextBox ID="DescriptionTextBox" runat="server" Text='&lt;%# Bind("Description") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:FileUpload ID="FileUploadDistrict" runat="server"/&gt;
  
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:DropDownList ID="CityFKDropDownList" runat="server" AutoPostBack="true" DataSourceID="ddlCityFK_DataSource" ViewStateMode="Enabled"
                      DataTextField="CityName" DataValueField="CityID"
                      AppendDataBoundItems="true"&gt;
                      &lt;asp:ListItem Text="-Stadt Wählen-" Value="0" &gt;&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
  
                  &lt;asp:EntityDataSource ID="ddlCityFK_DataSource" runat="server"
                      ConnectionString="name=MedicalEntities" DefaultContainerName="MedicalEntities"
                      EntitySetName="Cities"&gt;
                  &lt;/asp:EntityDataSource&gt; 
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/InsertItemTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;tr style="background-color:#DCDCDC;color: #000000;"&gt;
              &lt;td&gt;
                  &lt;asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /&gt;
                  &lt;asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DistrictIDLabel" runat="server" Text='&lt;%# Eval("DistrictID") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DistrictNameLabel" runat="server" Text='&lt;%# Eval("DistrictName") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DescriptionLabel" runat="server" Text='&lt;%# Eval("Description") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Image ID="DistrictImageLabel" runat="server" Height="100px" ImageUrl='&lt;%# "~/Handlers/ImageHandler.ashx?ID="+Eval("DistrictID")+"&amp;Entity=District"%&gt;'/&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="CityFKLabel" runat="server" Text='&lt;%# Eval("CityFK") %&gt;' /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/ItemTemplate&gt;
      &lt;LayoutTemplate&gt;
          &lt;table runat="server"&gt;
              &lt;tr runat="server"&gt;
                  &lt;td runat="server"&gt;
                      &lt;table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;"&gt;
                          &lt;tr runat="server" style="background-color:#DCDCDC;color: #000000;"&gt;
                              &lt;th runat="server"&gt;&lt;/th&gt;
                              &lt;th runat="server"&gt;DistrictID&lt;/th&gt;
                              &lt;th runat="server"&gt;DistrictName&lt;/th&gt;
                              &lt;th runat="server"&gt;Description&lt;/th&gt;
                              &lt;th runat="server"&gt;DistrictImage&lt;/th&gt;
                              &lt;th runat="server"&gt;CityFK&lt;/th&gt;
                          &lt;/tr&gt;
                          &lt;tr id="itemPlaceholder" runat="server"&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr runat="server"&gt;
                  &lt;td runat="server" style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;"&gt;
                      &lt;asp:DataPager ID="DataPager1" runat="server"&gt;
                          &lt;Fields&gt;
                              &lt;asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" /&gt;
                          &lt;/Fields&gt;
                      &lt;/asp:DataPager&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/LayoutTemplate&gt;
      &lt;SelectedItemTemplate&gt;
          &lt;tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;"&gt;
              &lt;td&gt;
                  &lt;asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" /&gt;
                  &lt;asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DistrictIDLabel" runat="server" Text='&lt;%# Eval("DistrictID") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DistrictNameLabel" runat="server" Text='&lt;%# Eval("DistrictName") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="DescriptionLabel" runat="server" Text='&lt;%# Eval("Description") %&gt;' /&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Image ID="DistrictImageLabel" runat="server" Height="100px" ImageUrl='&lt;%# "~/Handlers/ImageHandler.ashx?ID="+Eval("DistrictID")+"&amp;Entity=District"%&gt;'/&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:Label ID="CityFKLabel" runat="server" Text='&lt;%# Eval("CityFK") %&gt;' /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/SelectedItemTemplate&gt;
  &lt;/asp:ListView&gt; 
  
  &lt;asp:EntityDataSource ID="DistrictEntityDataSource" runat="server" ConnectionString="name=MedicalEntities" 
      DefaultContainerName="MedicalEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" 
      EnableUpdate="True" EntitySetName="Districts" Include="City" EntityTypeFilter="District"&gt;
  &lt;/asp:EntityDataSource&gt;
  </code></pre>
  
  <p>So I am trying to bind that dropdownlist values to the CityFK during Insert and Edit operations.</p>