i want to add items to a gridview in asp.net from a custom class. The class has Properties X and Y. Does anyone know if im able to add special attributes to these properties so i can just add the class and not have to muck around?
eg..
[Column("Name")]
public string Name { get; set; }
Ideally i can then write something like..
this.gridview.datasource = instanceOfMyClass;
Suppose you have a
DataObjectclass (equals toMyClassin your question)The DataSource of the gridview is not an instance of
DataObjectbut aList<DataObject>(or something equivalent), eachDataObjectrefers to one row in the grid view. On the other hand, it’s not a good idea to use attributes marked inDataObjectclass. Specifying theDataFieldin the columns of the grid view is the easiest way. Here is an example:And in code behind: