Link to home
Start Free TrialLog in
Avatar of ZURINET
ZURINET

asked on

Bind dataview from Class objects

Hi all
I am looking for a way to bind the below class object to a dataview

A tutorial or code snipet will be appreciated.
Please note.. I alread have a class that read the data from database..  
db connection topic is not relevant

Thanks in Advance

class Airplane
{
    public Airplane(string model, int fuelKg)
    {
        _id = ++lastID; Model = model; _fuelKg = fuelKg;
    }
    private static int lastID = 0;
    public int _id;
    public int ID { get { return _id; } }
    public int _fuelKg;
    public int FuelLeftKg { get { return _fuelKg; } set { _fuelKg = value; } }
    public string _model;
    public string Model { get { return _model; } set { _model = value; } }
    public List<Passenger> _passengers = new List<Passenger>();
    public List<Passenger> Passengers { get { return _passengers; } }
}
class Passenger
{
     public Passenger(string name)
    {
        _id = ++lastID; Name = name;
    }
     private static int lastID = 0;
    public int _id;
    public int ID { get { return _id; } }
    public string _name;
    public string Name { get { return _name; } set { _name = value

Open in new window

Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

I wrote this a while back.  It seems to fit fairly well with what you're asking.  The key being to cast your dataitem into the class object.
http://www.codepal.co.uk/show/How_to_DataBind_a_custom_class_object_to_a_GridView
Avatar of ZURINET
ZURINET

ASKER

Hi Rouchie
Thanks for the feedback..
I am looking for C# based solution.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAMIR BHOGAYTA
hi.. you can fill dataview with the help of this function. try this..

public object getdata(string str)
{
string constr;
constr = "ConnectionString";
SqlConnection con = new SqlConnection(constr);
con.Open();
object a;
SqlCommand cmd = new SqlCommand(str,con);
a = cmd.ExecuteScalar();
con.Close();
return a;
}
Avatar of ZURINET

ASKER

Not really what I was looking for..Guess should close this thread