This is a migrated thread and some comments may be shown as answers.
bind radgrid to enum datasource
2 Answers 66 Views
This is a migrated thread and some comments may be shown as answers.
Robert Jakech
Top achievements
Rank 1
Robert Jakech asked on 08 May 2010, 09:13 AM
Hi I have an enum method as follows
 public enum UserType
        {
            Default = 1,             
            Parameters = 2,
            Students = 3,
            Marks = 4,
            
  }
I need to bind enum values to a radgrid so that i have a display as follows

NAME             VALUES
Default              1
Parameters       2
Students           3
Marks               4

Please someone help me with the code snippets.

thanks.

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 12 May 2010, 02:49 PM
Hi Robert,

To archive the desired functionality please try the following code snippet:
void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    UserType type = new UserType();
    DataTable table = new DataTable();
    table.Columns.Add("Name");
    table.Columns.Add("Values");
    foreach (int i in Enum.GetValues(typeof(UserType)))
    {
        UserType parsedEnumValue = (UserType)Enum.Parse(typeof(UserType), i.ToString());
        table.Rows.Add(parsedEnumValue.ToString(), i.ToString());
    }
 
    RadGrid1.DataSource = table;
}

Additionally I am sending you a simple example which demonstrates the desired functionality. Please check it out and let me know if it helps you.

All the best,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Robert Jakech
Top achievements
Rank 1
answered on 12 May 2010, 07:13 PM
Dear Radoslav .

It has worked.

Thanks alot.
Long live Telerik Long Live RadControls!
Tags
Grid
Asked by
Robert Jakech
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Robert Jakech
Top achievements
Rank 1
Share this question
or