title: RadGrid - Can I set a column datafield property to an enum description?
body: <p>I am trying to bind a list of "Test" entities to the grid below.  I am able to get the User column to read the Name property on Person class by specifying <code>Person.Name</code> for the datafield.  </p>
  
  <p>However, when I try to get the Desc column to display the Enum value's description by setting the datafield property to <code>MyEnum.Description</code> I get nothing.  No errors, just a blank column.</p>
  
  <p>Is this possible?  Am I missing something? If I do this same kind of thing in the code-behind I would return a string of "Hello".</p>
  
  <p>I would prefer to <em>not</em> use the ItemDataBound event in the code behind if it can be helped.</p>
  
  <pre><code>Public Class Test
  
      Property MyPerson As Person
      Property MyEnum As HelloWorldEnum = HelloWorldEnum.Hi
  
      Public Enum HelloWorldEnum
          &lt;ComponentModel.Description("Hello")&gt; Hi
          &lt;ComponentModel.Description("World")&gt; Earth
      End Enum
  
  End Class
  
  Public Class Person
      Property Name As String
  End Class
  </code></pre>
  
  <p>A sample of my grid:</p>
  
  <pre><code>&lt;telerik:radgrid id="grid" runat="server"&gt;
      &lt;mastertableview&gt;
          &lt;Columns&gt;
              &lt;telerik:GridBoundColumn DataField="MyPerson.Name" HeaderText="User" /&gt;
              &lt;telerik:GridBoundColumn DataField="MyEnum.Description" HeaderText="Desc" /&gt;
          &lt;/Columns&gt;
      &lt;/mastertableview&gt;
  &lt;/telerik:radgrid&gt;
  </code></pre>
  
  <p><strong>Update:</strong> My apologies, I left out the fact that we have an extension method created to read the description attribute on the enum.  Hence my use of <code>.Description</code>.</p>
  
  <pre><code>&lt;Extension()&gt;
  Public Function Description(ByVal theEnum As [Enum]) As String
      Dim fi As FieldInfo = theEnum.GetType().GetField(theEnum.ToString)
      Dim attributes() As DescriptionAttribute = DirectCast(fi.GetCustomAttributes(GetType(DescriptionAttribute), False), DescriptionAttribute())
      If attributes.Length &gt; 0 Then
          Return attributes(0).Description
      Else
          Return theEnum.ToString
      End If
  End Function
  </code></pre>