Click here to Skip to main content
15,886,100 members
Articles / Web Development / ASP.NET

Populating custom business objects by binding business objects to a GridView using the ObjectDataSource in ASP.NET 2.0

Rate me:
Please Sign up or sign in to vote.
4.30/5 (18 votes)
20 Jan 20063 min read 113.3K   1.3K   51  
A complete article on how to populate custom business objects using a common method, binding these objects to a GridView using the ObjectDataSource control.
/*
 * Product Business Object
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

//Mapping Information
[MapInfo("ProductID", "ID")]
[MapInfo("Name", "Name")]
[MapInfo("ProductNumber", "Code")]
[MapInfo("FinishedGoodsFlag", "Finished")]
[MapInfo("Color", "Color")]
[MapInfo("StandardCost", "Cost")]
[MapInfo("Size", "Size")]
[MapInfo("ModifiedDate", "ModifiedDate")]
public class Product : AWBase
{
    private int id;
    private string name;
    private string code;
    private bool finished;
    private string color;
    private decimal cost;
    private string size;
    private DateTime modifiedDate; 
    //Properties    
    public int ID
    {
        get { return id; }
        set { id = value; }
    }
    
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    
    public string Code
    {
        get { return code; }
        set { code = value; }
    }
    
    public bool Finished
    {
        get { return finished; }
        set { finished = value; }
    }
    
    public string Color
    {
        get { return color; }
        set { color = value; }
    }

    
    public decimal Cost
    {
        get { return cost; }
        set { cost = value; }
    }
    
    public string Size
    {
        get { return size; }
        set { size = value; }
    }

    
    public DateTime ModifiedDate
    {
        get { return modifiedDate; }
        set { modifiedDate = value; }
    }
    //explict casting
    public Product AWBaseToProduct(AWBase pAWBase)
    {
        return (Product)pAWBase;
    }
    //Get Products
    public List<Product> GetProducts()
    {
        base.SqlSelectString = "select * from Production.Product";
        base.BusObjectType = this.GetType();        
        List<AWBase> list = base.LoadData();
        return list.ConvertAll<Product>(new Converter<AWBase,Product>(AWBaseToProduct));                
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
MCSD.NET Early Achiever,MCDBA SQL 2000,MCITP SQL 2005 Charter Member,MCPD Charter Member

Comments and Discussions