The data source of the gridview can be dataview, dataset, able, list, etc., as long as the data set conforms to the ilist interface.
There is nothing to say about the first few items. What's important is that list is not commonly used.
When list is used as the data source of the gridview, it must store a set of objects.
Common Errors
The data source of the gridview with the ID "gridview1" does not have any attributes or features that can be used to generate columns.
Causes and Solutions
The cause of this error is that the attributes in the object are not readable and writable. You only need to change the attributes of the object to readable and writable. The binding test is the same as that of dataset.
The following example:
// Class file
Ublic class studentinfo
{
Private int _ stuid;
Private string _ sname;
Private int _ Sage;
Public studentinfo ()
{
//
// Todo: add the constructor logic here
//
}
Public int stuid
{
Get {return _ stuid ;}
Set {_ stuid = value ;}
}
Public String sname
{
Get {return _ sname ;}
Set {_ sname = value ;}
}
Public int sage
{
Get {return _ Sage ;}
Set {_ sage = value ;}
}
}
// Binding method
Private void gvbind ()
{
List <studentinfo> List = new list <studentinfo> ();
Studentinfo AA = new studentinfo ();
AA. stuid = 1;
AA. sname = "AA ";
AA. Sage = 20;
Studentinfo BB = new studentinfo ();
BB. Sage = 21;
BB. sname = "BB ";
BB. stuid = 2;
Studentinfo cc = new studentinfo ();
Cc. stuid = 3;
Cc. sname = "cc ";
Cc. Sage = 23;
List. Add (AA );
List. Add (bb );
List. Add (CC );
Gridview1.datasource = List;
Gridview1.databind ();
}