The data source of the gridview can be dataview, dataset, able, list, etc., as long as the data set conforms to the ilist interface.

Source: Internet
Author: User

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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.