INFO: Roadmap for Web Forms Data Binding (313481)



The information in this article applies to:

  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET (included with the .NET Framework 1.1)
  • Microsoft ASP.NET (included with the .NET Framework)
  • Microsoft ASP.NET (included with the .NET Framework 1.1)

This article was previously published under Q313481

SUMMARY

This article provides a roadmap to learn and master data binding using ASP.NET Web Forms. To assist you with learning a Microsoft product or technology, roadmap articles provide links to useful information, including online documentation, Microsoft Knowledge Base articles, and white papers.

This article contains the following sections:
  • Overview
  • Architecture
  • QuickStart Tutorials
  • How To Articles
  • Walkthroughs
  • Troubleshooting
back to the top

Overview


With Web Forms pages, you can display information by binding controls to a source of data (as with most types of forms). However, data binding in Web Forms pages is somewhat different from data binding in other technologies, because of the nature of Web Forms pages themselves and the architecture of Web programming. With .NET Windows Forms and Web Forms, you can now bind to virtually any property of a control.

This topic provides background information about data binding in Web Forms pages, how to work with data binding in your Web applications, and where you can find more information about data binding and data access in Web Forms pages.

Data binding in Web Forms pages is flexible. You can bind any property of a control to data. This flexibility makes data binding in Web Forms pages different from previous types of date binding. In other types of data binding, you typically bind the display property (for example, the text property of a text box) to the data source.

In Web Forms pages, your data source can be almost any type of information that is available to the page, whether the information comes from a database, from an XML document, from another control or process, or even from a calculation that you perform yourself.

With Web Forms data binding you can assign this data to any property of any control. Therefore, you can use data binding to perform actions such as:
  • Set the text to display in a TextBox, Label, Button, LinkButton, or other control.
  • Set the target page (the HREF attribute) of a link control.
  • Bind a CheckBox control to a Boolean value to directly set the checked state of the control.
  • Set the graphic of an Image control by binding its ImageUrl property to a database column containing the URL or name of a graphics file.
  • Set the color, font, or size of controls. This can be useful as a way of implementing user preferences that you store in a database or other data store.
In other words, data binding is a way to automatically set any run-time accessible property of any control on the page.

For overview information about data binding by using ASP.NET Web Forms, visit the following Microsoft Web sites: For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

307860 ASP.NET Data Binding Overview

back to the top

Architecture

You can bind any single-value Web server control property to a data value (for example, you can bind the Text property of a TextBox or the ImageUrl property of an Image control). This includes not only display properties, but behavior properties such as size, width, and font. You specify single-value data binding by creating a data-binding expression. In Microsoft Visual Studio, you can use design-time tools to create this expression automatically. When the control performs data binding, it resolves the expression and assigns the resulting value to the specified property. You can data bind as many properties on a control as you want to.

For documentation about key Web Form data binding concepts, visit the following Microsoft Web sites:

Controls

Some Web Forms controls display values from multiple records at one time. These controls include the Repeater, DataList, DataGrid, ListBox, CheckBoxList, and RadioButtonList Web server controls, and the HtmlSelect control. Other controls, such as Label, TextBox, CheckBox, and Hyperlink controls, display single values, which in data-binding terms means values from a single record. For more information, visit the following Microsoft Web sites: The "Data-Binding Expressions for Web Forms Pages" Web site describes how Web Forms control data binding is specified through the use of a special syntax. The Web site covers the following topics:
  • Advantages of using data-binding expressions
  • Using the DataBinder class for binding
  • Resolving data-binding expressions

Control.DataBind Method

The Control.DataBind method binds a data source to the invoked server control and all its child controls. Use this method to bind data from a source to a server control. You typically use this method after you retrieve a data set through a database query. The "Control.DataBind Method" Web page also contains an example that demonstrates how to override the DataBind method in a custom control.

DataBinder Class

This Web site provides support for rapid-application development (RAD) designers to generate and parse Data Binding Expression Syntax. This class cannot be inherited.

DataBinder Members

This Web site has a list of all the DataBinder class members.

DataBinder.Eval Method

The DataBinder.Eval method uses reflection to parse and evaluate a data-binding expression against an object at run time. This method allows rapid-application development (RAD) designers, such as Visual Studio .NET, to easily generate and parse data-binding syntax. You can also use this method declaratively on a Web Forms page to simplify casting from one type to another. This Web site contains an example that shows how to use one of the overloaded versions of Eval.

Control.OnDataBinding Method

The Control.OnDataBinding method raises the DataBinding event. This method notifies a server control to perform any data binding logic that is associated with it. This Web site contains an example that demonstrates how to override the OnDataBinding method to add child controls to the parent control from a data source.

DataBinding Class

This Web site contains information about a single data-binding expression in an ASP.NET server control. This single data-binding expression allows RAD designers, such as Visual Studio .NET, to create data-binding expressions at design time. This class cannot be inherited.

DataBindingCollection Class

The DataBindingCollection class provides a collection of DataBinding objects for an ASP.NET server control. This class cannot be inherited. This Web site contains an example that demonstrates how to use the DataBindingCollection constructor.

DataBindingCollection Members

The "DataBindingCollection Members" Web site has a list of all members of the DataBindingCollection class.

Control.DataBinding Event

The Control.DataBinding event occurs when the server control binds to a data source. The event handler receives an argument of the EventArgs type that contains data that is related to this event. This event notifies the server control to perform any data binding logic that has been written for it.

IDataBindingsAccessor Interface

With the IDataBindingsAccessor interface, the collection of data-binding expressions on a control can be accessed at design time.

IDataBindingsAccessor Members

This Web site has a list of all the members of the IDataBindingsAccessor interface. back to the top

QuickStart Tutorials

For QuickStart tutorials, visit the following Microsoft Web sites: For more information about data binding server controls, visit the following Microsoft GotDotNet Web site: For more information about templated data-bound controls, visit the following Microsoft Web site: For more information about server controls, visit the following Microsoft Web site: back to the top

How To Articles

How To articles in the Microsoft Knowledge Base contain step-by-step instructions about how to do specific tasks. For additional information about data binding with ASP.NET Web Forms, click the article numbers below to view the articles in the Microsoft Knowledge Base:

308485 HOW TO: Create a Master/Detail Page with Web Form Controls

308485 HOW TO: Create a Master/Detail Page with Web Form Controls

306227 HOW TO: Use a CheckBox Web Control in a DataGrid

314334 HOW TO: Add Static Items to a DropDownList Control Using VB .NET

317429 HOW TO: Use the ItemDataBound Event in VB.Net Web Forms

317719 HOW TO: Export Data in DataGrid on an ASP. NET WebForm to Excel

313154 HOW TO: Create Summary Row for DataGrid in ASP.NET Using VB .NET

317794 HOW TO: Dynamically Create Controls in ASP.NET w/Visual C# .NET

back to the top

Walkthroughs

Walkthroughs are mini-tutorials that walk you through some typical application development scenarios using Web Forms data binding. For walkthrough documents, visit the following Microsoft Web sites: The "Using a DataGrid Web Control" walkthrough assists you with developing a templated data-bound control. It is easy to bind a property of a control to a single data item (or expression) by using ASP.NET data-binding syntax. This section addresses the more complex scenario of developing a control that has templated properties bound to a data source that is a collection type (System.Collections.ICollection or System.Collections.IEnumerable). Templates enable a page developer to customize the presentation of data that is bound to the control. The Repeater and DataList controls are examples of templated data-bound controls.

For additional information about how to develop templated data-bound controls, visit the following Microsoft Web site: back to the top

Troubleshooting

The Microsoft newsgroups and the Microsoft Knowledge are both valuable resources for troubleshooting.

In the Microsoft newsgroups, your peers can answer problems and questions. To view the Microsoft newsgroups, visit the following Microsoft Web site: To search for articles about specific issues in the Microsoft Knowledge Base (KB), visit the following Microsoft Web site: For additional information to help you with troubleshooting, visit the following Microsoft Web sites: back to the top

REFERENCES

For information about how to work with ASP.NET, view the ASP.NET QuickStart tutorial at the following Microsoft GotDotNet Web site: For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

313485 INFO: Roadmap for ADO.NET DataSet, DataView, and DataViewManager

back to the top

Modification Type:MajorLast Reviewed:8/12/2005
Keywords:kbArtTypeRoadmap kbDataBinding kbinfo KB313481 kbAudDeveloper