title: asp.net: How to better load Details view fields programmatically instead of copy/paste
body: <p>I have the following code for each lookup table. So far I am doing copy/paste for each drop down list control. But I think there is a better way of doing this. I should be able to specify<code> DataTextField</code>, <code>DataValueField</code>, control names etc. Of course, I will have to manually add configuration related database values on the database side like look up table, and other changes in the stored proc. But at the <code>.aspx</code> page or <code>.cs</code> page, there has to be a better way then copy/paste..</p>
  <pre><code>&lt;/asp:TemplateField&gt; 
   &lt;asp:TemplateField HeaderText=&quot;Your Ethnicity&quot;&gt;
      &lt;EditItemTemplate&gt;
          &lt;asp:DropDownList ID=&quot;ddlEthnicity&quot; runat=&quot;server&quot; 
              DataSourceid=&quot;ddlDAEthnicity&quot;
              DataTextField=&quot;Ethnicity&quot; DataValueField=&quot;EthnicityID&quot;
              SelectedValue='&lt;%#Bind(&quot;EthnicityID&quot;) %&gt;'&gt;
          &lt;/asp:DropDownList&gt;
      &lt;/EditItemTemplate&gt;
      &lt;ItemTemplate &gt;
          &lt;asp:Label Runat=&quot;server&quot; Text='&lt;%# Bind(&quot;Ethnicity&quot;) %&gt;' 
              ID=&quot;lblEthnicity&quot;&gt;
          &lt;/asp:Label&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;     
  </code></pre>