BINDING (System.Collections.Generic.List) TO GRIDVIEW
THIS EXAMPLES HELPS TOU TO BIND DATAGRID WITH System.Collections.Generic.List ARRAY
PLACE A DATAGRID IN THE DEFAULT.ASPX PAGE AND WRITE THE FOLLOWING CODE
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class classCric : System.Web.UI.Page
{
//this is class
public class cricket
{
private int no;
private string cname;
private string country;
// this is property
public int no1
{
get
{
return no;
}
set
{
no = value;
}
}
public string cname1
{
get
{
return cname;
}
set
{
cname = value;
}
}
public string country1
{
get
{
return country;
}
set
{
country = value;
}
}
public cricket(int no1, string cname1, string country1)
{
this.no = no1;
this.cname = cname1;
this.country = country1;
}
}//end of cricket class
protected void Page_Load(object sender, EventArgs e)
{
System.Collections.Generic.List<cricket> cric = new System.Collections.Generic.List<cricket>();
cric.Add(new cricket(1, "dhoni", "india"));
cric.Add(new cricket(1, "afridi", "pak"));
cric.Add(new cricket(1, "mindas", "sl"));
GridView1.DataSource = cric;
GridView1.DataBind();
}
}
This coding is not working