Hi,
Let me explain the implementation first. Below is the base classes that I am using
public class DataClass
{
public string name;
public int member;
}
Following will give the data to the GridView
public class DataFields
{
public static List<DataClass> getData()
{
List<DataClass> dataList = new List<DataClass>();
for (int i = 1; i < 10; i++)
{
DataClass data = new DataClass();
data.name = "H" + i;
data.member = i;
dataList.Add(data);
}
return dataList;
}
}
Following is the aspx page class
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = DataFields.getData();
GridView1.DataBind();
}
}
Though this is a simple implementation I got
"gridview did not have any properties or attributes" error. But I solved this by implementing the DataClass in the following way
public class DataClass
{
public string name { get; set; }
public int member { get; set; }
}
I want to know why there is no error this time as I m using both the variables as public even before. I know it is not necessary to use the getter and setter method in all case. But I want to know why do we have to use under the above case.