
168
|
Chapter 7: Data Access and Data Binding
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Binding to DataViews
Binding to richer data sources, such as DataTables and DataViews, is even more
powerful than binding to collections, though still relatively simple. The
DataView
class provides a representation of the data in a DataTable that can be sorted and
filtered, and also implements the necessary interfaces that allow it to be
databound. These data sources can be used by:
• Retrieving data in a dataset and binding to the constituent DataTables
• Building DataViews, based on the data in the data table, or retrieving the
table’s
DefaultView property, which returns an unsorted, unfiltered DataView
• Creating DataTables and/or DataViews programmatically
Binding a
DataTable or DataView to controls such as DataGrid, DataList, and
Repeater provides an extremely powerful technique for displaying and editing
data with a minimum of code. It also provides substantial flexibility in how the
data is formatted and displayed.
The examples in the sections “Inserting and Updating Data” and “Deleting Data”
demonstrate how to bind the default
DataView of a table to a DataGrid for display.
Inserting and Updating Data
Reading and binding data is all very well, but for most applications, it’s only part
of what the application needs to do. Another important