title: ASP.Net - DropDownList used in EditItemTemplate in DetailsView
body: <p>I have a problem with <em>DetailsView</em>. I need to use <em>DropDownList</em> for update values in databaze. These values I've got in a different table. I use an ObjectDataSource and it works properly. My problem is how to use the DropDownList when I cannot bind the <em>SelectedValue</em> in the designer because it's missing. I found many advices like</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlEditPermissions" runat="server" DataSource='&lt;%#getPermissions() %&gt;' SelectedValue='&lt;%# Bind("PermissionID") %&gt;'/&gt;
  </code></pre>
  
  <p>But as I wrote the SelectedValue property is not allowed in designer. I'm looking for another way to <em>SelectedValue='&lt;%# Bind("PermissionID") %>'</em> because I wanna use DropDownList SelectedValue property as parametr for the ObjectDataSource UpdateMethod.</p>
  
  <p>My update method:</p>
  
  <pre><code>    public static void UpdateUser(int UserId, string UserName, int PermissionID)
      {
          using (DC_databazeDataContext db = new DC_databazeDataContext())
          {
              if (!db.DatabaseExists())
                  throw new Exception("Databáze neexistuje nebo se k ní nedá připojit!");
  
              var users = db.USERs.Where(u =&gt; u.USER_ID == UserId);
  
              if (users.Count() == 0) return;
  
              USER aktU = users.First();
  
              aktU.USER_NAME_A = UserName;
              aktU.OPRAVNENI_ID = PermissionID;
  
              db.SubmitChanges();
          }
      }
  </code></pre>
  
  <p>Here is my DetailsVeiw:</p>
  
  <pre><code>&lt;asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" DataSourceID="ODS_UzivatelDetail" DataKeyNames="UserId"&gt;
      &lt;Fields&gt;
          &lt;asp:BoundField DataField="UserId" HeaderText="UserId" SortExpression="UserId" ReadOnly="true" /&gt;
          &lt;asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" /&gt;
          &lt;asp:TemplateField HeaderText="PermissionID" SortExpression="PermissionID"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:DropDownList ID="ddlEditPermissions" runat="server" DataSource='&lt;%# getPermissions() %&gt;'/&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="lPermissions" runat="server" Text='&lt;%# Bind("PermissionID") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:CommandField ShowEditButton="True" /&gt;
      &lt;/Fields&gt;
  &lt;/asp:DetailsView&gt;
  </code></pre>
  
  <p>DB tables:</p>
  
  <p><strong>Users</strong></p>
  
  <ul>
  <li>USER_ID - <em>int</em> </li>
  <li>PERMISSION_ID - <em>int</em> </li>
  <li>USER_NAME_A - <em>nvarchar(20)</em></li>
  </ul>
  
  <p><strong>Permissions</strong></p>
  
  <ul>
  <li>PERMISSION_ID - <em>int</em></li>
  <li>PERMISSION_NAME_A - <em>nvarchar(20)</em></li>
  </ul>
  
  <p>I'm using VS2012 .Net Framework 4.5... 
  So could anyone help me?</p>