O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required