Home > DeveloperSection > Forums > How to bind List<T> data in devexpress XtraGrid control?
Carl Pieterson
Carl Pieterson

Total Post:14

Points:98
Posted on    June-13-2012 1:54 AM

 C# C# 
Ratings:


 1 Reply(s)
 19504  View(s)
Rate this:

Hello,

I want to bind data in devexpress grid control through generic list.
Can anyone explain me how can I acheive this task?

Thanks.



Chris Anderson
Chris Anderson

Total Post:65

Points:455
Posted on    June-13-2012 2:03 AM

hi,

you can achieve this task by using the code given below:

Fisrt step: Create a class and add some properties:

public class Sample
{
      public string Name { get; set; }
      public int Age { get;set; }
}

Second step: Add some sample data in the list

using System.Collections;

List<Sample> list =new List<Sample>();

list.Add( new Sample
{
      Name="Rohit",
      Age=20
});

list.Add( new Sample
{
      Name="Rohit",
      Age=20
});

Third Step: Bind list as datasource of gridcontrol.

gridControl1.DataSource = list;

Note:You also have to add the two fields in devexpress gridview and provide the FieldName of column as name of the property.




Modified On Jun-14-2012 03:57:58 AM

Don't want to miss updates? Please click the below button!

Follow MindStick