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

[Solved] Display enum value in row?

1 Answer 303 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 18 Mar 2010, 02:35 PM
Hi - I have an integer value that is being pulled from my db and displayed in my grid like this:

 <telerik:GridBoundColumn DataType="System.Int32" UniqueName="UserAccountStatus" 
                        SortExpression="UserAccountStatus" HeaderText="Status" DataField="UserAccountStatus"></telerik:GridBoundColumn>   

But that value is actually the numeric value of an enum. So - rather than displaying the numeric value of the enum, I need to display the text value of the enum.

How do I do this?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Mar 2010, 07:07 AM

Hello,

You can get the text value for the corresponding numeric value inside ItemDataBound Event.
Check the following sample code.

C#:
public enum UserAccountStatus 
    Active = 1, 
    InActive, 
    Blocked 
protected void RadGrid3_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    
    if (e.Item is GridDataItem) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        DataRowView row = (DataRowView)item.DataItem; 
        int enumVal = Convert.ToInt32(row["UserAccountStatus"].ToString()); 
        UserAccountStatus enumString = (UserAccountStatus)enumVal; 
        item["UserAccountStatus"].Text = enumString.ToString(); 
    } 

-Shinu
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or