ASP.NET Object Data Source


Example

<asp:ObjectDataSource ID="ObjectDataSourceEmployees" runat="server"
    TypeName="MyPackage.MyDataAccessClass"                       
    DataObjectTypeName="MyPackage.Employee" 
    SelectMethod="GetEmployees"
    UpdateMethod="SaveEmployee"
    InsertMethod="SaveEmployee">
</asp:ObjectDataSource>

In the code behind

The Data Access Class

public class MyDataAccess
{
    public static List<Employee> GetEmployees()
    {
        List<Employee> results = new List<Employee>()
        {
            new Employee(){ Id=1, Name="John Smith" }, 
            new Employee(){ Id=2, Name="Mary Jane" } 
        };
    
        return results;
    }  

    public static void SaveEmployee(Employee e)
    {
        // Persist Employee e to the DB/cache etc. here
    }        
}

The Employee Class

public class Employee
{
    public Int32EmployeeId { get; set; }
    public string Name { get; set; }
}