ASP.NET Data Binding
ASP.NET
data binding differs dramatically from Windows Forms data binding.
The key difference is that ASP.NET data binding takes place on the
server side when the page is loaded. However, there is no mechanism
to apply the data binding to the rendered HTML page that is sent to
the user. Thus, there is no way to implement synchronized controls or
editable data objects (although this can be simulated). ASP.NET
binding is strictly one-way; data can flow from a
DataSet
into a control but not vice versa.
Because of a web application’s stateless nature,
ASP.NET data binding is less powerful than Windows Forms data
binding. However, ASP.NET makes up for the loss by including several
advanced template-based controls, such as the
DataGrid
, DataList
, and
Repeater
. These controls have a much more
customizable interface and offer many features the Windows
DataGrid
doesn’t.
The data binding process in an ASP.NET page works like this:
You define the bindings, using similar syntax to what you use when binding a Windows form.
You trigger data binding for individual controls or the entire page by calling the
DataBind( )
method. At this point, the information moves from the data objects to the controls.The final page is rendered to HTML. The data objects are discarded.
The page is posted back at a later point, perhaps in response to an editing action the user has performed with a data-bound control. At this point, you must requery the database, re-create the ADO.NET objects, and ...
Get ADO.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.