Using DataGrids with ORM.NET

A common task when developing data driven applications involves displaying data using data grids, data lists or repeater controls. The collection classes that ORM.NET generates for the table objects make working these types of controls easy to use.

 

For example, to the bind an ORM.NET generated Collection object to an ASP.NET DataGrid control called DataGrid1 see the following code section.

 

Refer to the Sample Applications to view more complex examples of working with DataGrids

 

 

 

DataManager dm = new DataManager(Config.Dsn)

 

// return all the students for display in a grid

StudentCollection students = dm.GetStudentCollection();

 

//Bind the students object to the DataSource and optionally sort by Student LastName in Ascending order

DataGrid1.DataSource = students.SortByLastName(SortDirection.Ascending);

 

DataGrid1.VirtualItemCount = students.Count();   // required to implement paging on the ASP.NET DataGrid

 

DataGrid1.DataBind();  // bind the Student Collection

 

 

You can now define the required DataBound Column and other settings you desire to control the display and functionality of the DataGrid.