How to bind ArrayList Object to an ASPxGridView control

I have been involved with a ASP.Net project recently and I have implemented it using the awesome DevExpress ASP.Net controls. 

Parts of the project involved binding data from custom objects, SqlDataSource & ObjectDataSource data sources to the ASPxGridView control.

In this post I will show you how to bind data from an ArrayList object to the ASPxGridView control.

If you want to implement this example you need to download the trial version of these controls unless you are a licensed holder of DevEpress products. 

1) Launch Visual Studio 2010 (express edition will work fine). Create a new empty website and choose a suitable name for it. Choose C# as the development language.

2) Add a new item to your site, a web form. Leave the default name, Default.aspx

3) Drag and drop a ASPxGridView control on the form. I am using the latest build from DevEpress which is 11.2.11 

4) In the Page_Load event handling routine of the Default.aspx page type

    protected void Page_Load(object sender, EventArgs e)
       ASPxGridView1.Caption = "Famous Footballers";
       ASPxGridView1.DataSource = Footballers();

5) Now we need to implement the Footballers() method.


  private ArrayList Footballers()
        ArrayList newfootballers = new ArrayList();
        newfootballers.Add("Steven Gerrard");
        newfootballers.Add("Frank Lampard");
        newfootballers.Add("John Terry");
        newfootballers.Add("Lionel Messi");
        newfootballers.Add("Cristiano Ronaldo");
        newfootballers.Add("Dirk Kuyt");
        newfootballers.Add("David Beckham");
        newfootballers.Add("Pepe Reina");
        newfootballers.Add("Paul Scholes");
        newfootballers.Add("Roy Keane");
        newfootballers.Add("Ryan Giggs");
        newfootballers.Add("Daniel Alves");
        newfootballers.Add("Cesc Fabregas");
        newfootballers.Add("Andres Iniesta");
        newfootballers.Add("Michael Owen ");
        return newfootballers;

6) Build and run your application.The ArrayList object binds to the ASPxGridView control and we have sorting and paging out of the box.

Hope it helps!!!

1 Comment

Comments have been disabled for this content.