Binding Data to Controls

for RuBoard

List controls are components that provide certain UI capabilities such as a data list or data grid. There are two base classes for controls. These are System.Windows.Forms.Control (client-side Windows Forms controls) and System.Web.UI.Control (ASP.NET server controls). All controls in the .NET Framework class library derive directly or indirectly from these two classes.

Remember, these controls provide UI capabilities, but they do not populate data from a data source. This is done by binding data from a data source to a list control. In ADO.NET, you can bind not just to traditional data sources, but to almost any structure that contains data. You still have to create connections and data adapters to populate the data structures you choose to work with (datasets, arrays, and so on). Using data binding far outweighs having to code the retrieval and mapping of data to a control manually (the way we had to do in the olden days).

Simple Data Binding

When you only need to have a control display a single value, like that of a TextBox control, this limited usage is referred to as "simple data binding." Simple data binding is the ability to bind a control to a single data element (such as a value in a column in a DataSet table). There are tons of simple data bindings going on in applications ”by far the most common data binding you will see.

Complex Data Binding

When you need to display and manipulate more than one data element at a time, like that in ListBox es and DataGrid s, this extended usage is referred to as "complex data binding." Complex data binding is the ability to bind a control to more than one data element and more than one record in a database.

BindingContext and CurrencyManager Objects

Any data source ”whether it is an array, a collection, or a data table that you bind a control to ”will have an associated CurrencyManager object that will keep track of the position and other bindings to that data source. So, you might have one CurrencyManager object keeping track of several text boxes because they are all bound to the same data table. This means that the data in each of the text boxes that are bound to the same data source will show the right data at the right time (the data that belongs together).

Of course, there will be multiple CurrencyManager objects if there are multiple data sources. Then there is a BindingContext object that sits on top of all the CurrencyManager s. It is this BindingContext object that manages all of the CurrencyManager objects for a Windows form that you are developing.

Data Binding Scenarios

Virtually every application you develop will be a candidate for using data binding if the applications must access some type of data source for information or have to manipulate data from a data source. Typical scenarios might be

  1. Any report or printed document that must be generated from a data source and formatted into columns of lists.

  2. Data entry forms that use text boxes, drop-down lists, and so on.

  3. Parent and child data relationship of any kind such as you would find with customers and their orders, orders and their order details, parts and related accessories, and so on. These types of data fit nicely into DataGrid representations.

Class Hierarchies Relevant to Data Binding

Text box controls ”Used to display, or accept as input, a single line of text. Can also support multilines .

  • System.Windows.Forms.TextBox class

    • System.Windows.Forms.DataGridTextBox subclass

  • System.Web.UI.WebControls.Textbox class

List controls ”Enable you to display a list of items to the user that the user can select by clicking.

  • System.Windows.Forms.ListControl class

    • System.Windows.Forms.ComboBox subclass

    • System.Windows.Forms.ListBox subclass

  • System.Web.UI.WebControls.ListControls class

    • System.Web.UI.WebControls.CheckBoxList subclass

    • System.Web.UI.WebControls.DropDownList subclass

    • System.Web.UI.WebControls.ListBox subclass

    • System.Web.UI.WebControls.RadioButtonList subclass

DataGrid controls ”Used to display data in a scrollable, tabular grid.

  • System.Windows.Forms.DataGrid class

  • System.Web.UI.WebControls.DataGrid class

for RuBoard


Sams Teach Yourself ADO. NET in 24 Hours
Sams Teach Yourself ADO.NET in 24 Hours
ISBN: 0672323834
EAN: 2147483647
Year: 2002
Pages: 237

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