Using AutoGenerateColumns to generate Datagrid columns

A

Amrut Kale

I have an arraylist which contains FlightDetails objects

public class FlightDetails {
public string flightId;
public string airline;
public string fromCity;
public string toCity;
public System.DateTime date;
public int numSeatsAvailable;
public System.Double ticketFare;
}

When I try to use the the DataGrid as follows:


flights = new ArrayList()

/* code to populate the flighs arraylist - it just creates
a set of new FlightDetails objects and adds them into
the
array */

datagrid.DataSource = flights;
datagrid.Databind();

When the call to databind happens, it generates an error
saying that DataGrid with id 'flights' could not
automatically generate any columns from the selected data
source.

Is it possible to use the datagrid to automatically
generate the columns using the above structure without
having to convert the arraylist into a DataSet? If so
how ?

If not, what would be the best way to display the above
structure so that I won't have to change the display code
if I add or remove a few fields in future.

regards, amrut.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top