This is a migrated thread and some comments may be shown as answers.

[Solved] Binding DropDownColumn with Enum property

1 Answer 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allin
Top achievements
Rank 1
Allin asked on 16 Jul 2013, 01:58 PM
Hi,

I trying to bind a dropDownColumn to a class property as Enum and the value in itemDataBound always nbsp. When i bind with BoundColumn it's ok, i see the value of the enum.

If i change the class property to integer, the dropDownColumn displayed correctly, but i want to keep the class property as enum.  

Any workaround for this?

'Do not work
Public class XYZ
    Public Property Status as StatusEnum
End Class
 
Public Enum StatusEnum as Integer
    Enabled = 0
    Disabled = 1
End Enum
 
'Work
Public class XYZ
    Public Property Status as Integer
End Class

ty

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 19 Jul 2013, 07:20 AM
Hi Pat,

In order to achieve your scenario you could define a GridTemplateColumn place a RadComboBox and set its DataSource property and data bind it in the RadGrid ItemDataBound event as shown below.
Protected Sub rgGrid_ItemDataBound(sender As Object, e As GridItemEventArgs)
    Dim dataItem As GridDataItem = TryCast(e.Item, GridDataItem)
    If dataItem IsNot Nothing Then
        Dim item As XYZ = TryCast(dataItem.DataItem, XYZ)
        Dim combo As RadComboBox = TryCast(dataItem.FindControl("RadComboBox1"), RadComboBox)
        combo.DataTextField = "Name"
        combo.DataValueField = "Name"
        combo.DataSource = [Enum].GetNames(GetType(StatusEnum)).[Select](Function(name) New With { _
            .Name = name _
        })
        combo.DataBind()
    End If
End Sub

Regards,
Antonio Stoilkov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Allin
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or