top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

how to bind arraylist with gridview control in asp net application

0 votes
69 views
how to bind arraylist with gridview control in asp net application
posted May 23, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

We will create a class named Item as shown below. In the Page_Load method, we will create an ArrayList and add items to the arraylist using Add method. Now we will bind the arrayList using GridView.DataSource property.

public class Item
 {
     private string strCode;
     private string strName;

     public Item(string code, string name)  
     {
        this.strCode = code;
        this.strName = name;            
     }      

    public string Code     
    {        
      get 
      {   return this.strCode;    }      
    }
    public string Name
    {
       get
       {    return this.strName; }
       }
    }
}

protected void Page_Load(object sender, EventArgs e)
 {
    ArrayList list = new ArrayList();
    list.Add(new Item("I001", "Item1"));
    list.Add(new Item("I002", "Item2"));
    list.Add(new Item("I003", "Item3"));
    list.Add(new Item("I004", "Item4"));

    GridView1.DataSource = list;
    GridView1.DataBind();
 }
answer May 23, 2016 by Shivaranjini
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...