title: gridview bind dropdownlist to List<keyvaluePair<int, string>>
body: <p>I have a number of tables in my DB that hold references to an key value pair:</p>
  
  <p>types of phone  numbers:</p>
  
  <ul>
  <li>1 - Home</li>
  <li>2 - Work</li>
  <li>3 - Mobile</li>
  <li>4 - Fax</li>
  </ul>
  
  <p>etc</p>
  
  <p>So I have a table for the types and when they are used in other tables they reference the int value as a foreign key.  When I have been pulling them out I have been storing them as <code>keyvaluepair&lt;int, string&gt;</code> items in the class that is using them.</p>
  
  <p>When I needed to get a list of them I thought I would just create a List&lt;> of them rather than use two different types of data types to get the same data.</p>
  
  <p>My problem has arrived when I need to populate a dropdownlist within a gridview when I am using the edittemplate bit.  If I use a datasource to pull this out it will write [1 Home] in the text rather than put the int as the value and Home as the text to display.</p>
  
  <p>I guess I have a multiple part question really.</p>
  
  <p>One:</p>
  
  <p>Am I being stupid?  Is this a really bad way to get the data out and store it (the keyvaluepair part)?  Should I just be storing it all in a datatable?  I didn't like to put it all in datatable.  I have my DAL taking to my BLL and have tried to encapsulate everything as objects or <code>List&lt;&gt;</code>'s of objects rather than tables of everything.  Most the time this has worked well.</p>
  
  <p>Two:</p>
  
  <p>If I was using some object rather than a datatable to bind into my objectdatasource for the dropdownlist, how can I set the currently selected value, rather than have it just have the first item in the list selected?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As was pointed out below I was being an idiot and just needed to set the DataValueField and DataKeyField.</p>
  
  <p>To get the dropdownlist to bind I just had to do:</p>
  
  <pre><code>SelectedValue='&lt;%# DataBinder.Eval(Container, "DataItem.PhoneType.Key") %&gt;'
  </code></pre>
  
  <p>The reason I didn't see that one straight away was because it was not showing up in my intellisense but when I manually typed it in, it worked.</p>