title: Adding an extra property to the asp.net DropDownList
body: <p>I'm trying to extend the DropDownList control to simply add one extra property.</p>
  
  <p>Code as follows</p>
  
  <pre><code>Public Class CustomDropDownList
      Inherits DropDownList
  
      Private key As Int32
  
      Public Property PrimaryKey() As Int32
          Get
              Return key
          End Get
          Set(ByVal value As Int32)
              key = value
          End Set
      End Property
  
  End Class
  </code></pre>
  
  <p>Although that includes a lot of cut/paste from other sources, it seems fairly simple, I've added a local variable, and then the property's get/set statements.</p>
  
  <p>Is there anything wrong with this?  I'm having issues with the get returning 0 even though I've performed the set prior to this. </p>
  
  <p>cheers! :D</p>
  
  <p>EDIT:</p>
  
  <p>For clarity, I'm using a repeater with my customDropDownList, and in its ItemDatabound event, I do the following</p>
  
  <pre><code>If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
          Dim row As DataRowView = e.Item.DataItem
          Dim cdlConst As CustomDropDownList = e.Item.FindControl("cdlConstituencies")
          cdlConst.SelectedValue = row.Item("constituencyrefno")
          cdlConst.PrimaryKey = row.Item("uniqueid")
  End If
  </code></pre>
  
  <p>But then if I access the primaryKey property at a later time, I get 0.. selectedValue and all the rest work fine.</p>