INFO: Roadmap for Web Forms Data Binding

Article translations Article translations
Article ID: 313481 - View products that this article applies to.
This article was previously published under Q313481
Expand all | Collapse all

On This Page

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

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:
Web Forms Data Binding
Introduction to Data Binding in Web Forms Pages
Data-Binding Expressions for Web Forms Pages
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
307860 ASP.NET Data Binding Overview

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:
Data Binding Single-Value Web Server Controls at Design Time
Data Binding Single-Value Web Server Controls at Run Time

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:
Multi-Record and Single-Value Data Binding for Web Forms Pages
Data-Binding Expressions for Web Forms Pages
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

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

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

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

DataBinder.Eval Method

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

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

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

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

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

Control.DataBinding Event

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

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

IDataBindingsAccessor Members

IDataBindingsAccessor Members
This Web site has a list of all the members of the IDataBindingsAccessor interface.

QuickStart Tutorials

For QuickStart tutorials, visit the following Microsoft Web sites:
ASP.NET QuickStart
ASP.NET Data Binding
For more information about data binding server controls, visit the following Microsoft GotDotNet Web site:
Data Binding Server Controls
For more information about templated data-bound controls, visit the following Microsoft Web site:
Sample Templated Data-Bound Control
For more information about server controls, visit the following Microsoft Web site:
Server Control Samples

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

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:
Walkthrough: Updating Data Using a Database Update Query in Web Forms
Walkthrough: Using a DataGrid Web Control to Read and Write Data
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:
Developing a Templated Data-Bound Control

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:
MSDN Newsgroups
To search for articles about specific issues in the Microsoft Knowledge Base (KB), visit the following Microsoft Web site:
Microsoft Knowledge Base
For additional information to help you with troubleshooting, visit the following Microsoft Web sites:
MSDN Library
MSDN Online .NET Developer Center

REFERENCES

For information about how to work with ASP.NET, view the ASP.NET QuickStart tutorial at the following Microsoft GotDotNet Web site:
ASP.NET QuickStart Tutorial
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

Properties

Article ID: 313481 - Last Review: March 29, 2007 - Revision: 5.5
APPLIES TO
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET 1.1
  • Microsoft ASP.NET (included with the .NET Framework)
  • Microsoft ASP.NET 1.1
Keywords: 
kbarttyperoadmap kbdatabinding kbinfo KB313481

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com