Hi,
I'm trying to extend the DropDownList control to simply add one extra property.
Code as follows
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
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.
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.
cheers! :D
EDIT:
For clarity, I'm using a repeater with my customDropDownList, and in its ItemDatabound event, I do the following
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
But then if I access the primaryKey property at a later time, I get 0.. selectedValue and all the rest work fine.