21.6. Using Recordsets with DataGrids

Problem

You want to display recordset data in a grid.

Solution

Use the DataGrid component.

Discussion

The DataGrid component is available for purchase from Macromedia as part of the DevNet Resource Kit (DRK) Volume 1, available from http://www.macromedia.com/software/drk/productinfo/product_overview/volume1. It is invaluable for displaying complex data sets such as recordsets. Normal menus, such as list boxes, work great for showing one-dimensional lists of values, but when it comes to displaying two-dimensional (row and column) data, they are not up to par. The DataGrid component allows you to display data as rows and columns, and with the DataGrid.setDataProvider( ) method or the DataGlue class, you can populate a data grid with recordset data in short order.

The setDataProvider( ) method populates the data grid with data from a recordset. If the data grid has no defined columns, columns that match the columns of the recordset in name and order are automatically created.

#include "NetServices.as" // Create a new recordset with columns ID, FIRST, LAST. rs = new RecordSet(["ID", "FIRST", "LAST"]); rs.addItem({ID: 24, FIRST: "Bob", LAST: "Bobson"}); rs.addItem({ID: 42, FIRST: "Sarah", LAST: "Littlefoot"}); rs.addItem({ID: 66, FIRST: "George", LAST: "Georgeman"}); // Set the data grid to alternate row colors between white and light blue. myDataGrid.alternateRowColors(0xFFFFFF, 0xC1E0FD); // Populate the data grid with the recordset data. It creates ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.