Skip to main content

Posts

Showing posts from July 15, 2012

Add data to GridView and Export GridView data to Excel sheet

Suppose , you have data stored in a array of structure. let us say,    public struct myData    {       string name;       int age;       string city;      public myData(string pName,int pAge,string pCity)         {           name=pName;           age=pAge;           city=pCity;         }     } ............... public void dataTableData() {        List<myData> items=new List<myData>();        ...add name,age,city of each person to the object 'data'.    //Now you need to add data present in the object 'items' to the GridView DataTable table=new DataTable(); DataRow row=null; //Create three columns 'Name','Age','City' table.Columns.Add(new DataColumn("Name",typeOf(string)); table.Columns.Add(new DataColumn("Age",typeOf(int)); table.Columns.Add(new DataColumn("City",typeOf(string)); //Now loop through the items present in the object 'items' foreach(myData item in