Handling Data Binding

Binding data to controls in Windows and Web forms is a big topic in .NET programming. So big that Microsoft has made all Windows controls data-aware, which means you can bind them to data sources. For example, you might bind the au_lname field from the authors table to a text box. At runtime, the current author's last name will appear in that text box. Or you might bind the au_id field to a list box, which will make all the author IDs appear in the list box. Or you might bind the whole authors table to a data grid.

You can bind any property of any control to a data source, and we're going to see how that works here. After binding a dataset or data view to controls in a form, you can navigate through the data in that dataset or data view, and the data that appears in the bound controls will be updated automatically as you move from record to record. You'll often see bound controls used in data-entry forms, forms that let the users navigate through a dataset, master/detail forms (in which, for example, the users can use one control to specify the state they want to find authors from, making the other controls automatically display the authors from that state), and so on.

To understand data binding in concrete terms, take a look at the Ch09_05 example, which you can see at work in Figure 9.25. This example binds various controls to the last name of authors in the authors table in the SQL Server pubs example database. You can use the buttons at the bottom to navigate through the authors table, and as you do, each bound control will display the last name of the current author. We're going to dissect this example piece by piece next .

Figure 9.25. The Ch09_05 example.


There are actually two types of bindingsimple binding and complex binding. We'll start by addressing the difference between these two.

Microsoft Visual C#. NET 2003 Kick Start
Microsoft Visual C#.NET 2003 Kick Start
ISBN: 0672325470
EAN: 2147483647
Year: 2002
Pages: 181

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net