Data Binder

Posted by Arvin under
Data Binding
Data binding is the ability to take data returned from a database, API, or service (such as
a data service) and render the data into some UI markup without the need to write lengthy
code. Data binding support in ASP.NET controls comes in two parts: controls that expose
properties that you can bind data to and controls that support collections of data to repeat
markup for each item in any collection that implements 􀁅􀁁􀁪􀁱􀁩􀁡􀁮􀁝􀁞􀁨􀁡.
Data binding against properties on an ASP.NET control is handled in markup using a
binding expression. A binding expression syntax is 􀀸􀀡􀀟􀀜􀁁􀁴􀁬􀁮􀁡􀁯􀁯􀁥􀁫􀁪􀀜􀀡􀀺, where the contents
of this complete expression are replaced by the data contained in the expression.
All ASP.NET controls that can be bound to a collection of data inherit from 􀁀􀁝􀁰􀁝􀀾􀁫􀁱􀁪􀁠􀀿􀁫􀁪􀁰􀁮􀁫􀁨.
Such example controls include the 􀁃􀁮􀁥􀁠􀁒􀁥􀁡􀁳 control, the 􀁈􀁥􀁯􀁰􀁒􀁥􀁡􀁳 control, and the 􀁀􀁝􀁰􀁝􀁈􀁥􀁯􀁰
control. Controls that inherit from the 􀁀􀁝􀁰􀁝􀀾􀁫􀁱􀁪􀁠􀀿􀁫􀁪􀁰􀁮􀁫􀁨 provide two different ways of binding
a collection of data to the control: either programmatically or using ASP.NET markup.
To implement data binding using ASP.NET markup, the 􀁀􀁝􀁰􀁝􀀾􀁫􀁱􀁪􀁠􀀿􀁫􀁪􀁰􀁮􀁫􀁨 exposes a property
named 􀁀􀁝􀁰􀁝􀁏􀁫􀁱􀁮􀁟􀁡􀁅􀁀, which should be set in markup to point to a control that inherits
from 􀁀􀁝􀁰􀁝􀁏􀁫􀁱􀁮􀁟􀁡􀀿􀁫􀁪􀁰􀁮􀁫􀁨. Data source controls are nonvisual controls used to retrieve data
from the underlying data source in ASP.NET markup. Example data source controls include
the 􀁋􀁞􀁦􀁡􀁟􀁰􀁀􀁝􀁰􀁝􀁏􀁫􀁱􀁮􀁟􀁡 and the 􀁏􀁭􀁨􀁀􀁝􀁰􀁝􀁏􀁫􀁱􀁮􀁟􀁡.
The second method of implementing data binding using a 􀁀􀁝􀁰􀁝􀀾􀁫􀁱􀁪􀁠􀀿􀁫􀁪􀁰􀁮􀁫􀁨 is to execute
data binding programmatically. To achieve this, the 􀁀􀁝􀁰􀁝􀀾􀁫􀁱􀁪􀁠􀀿􀁫􀁪􀁰􀁮􀁫􀁨 exposes a 􀁀􀁝􀁰􀁝􀁏􀁫􀁱􀁮􀁟􀁡
property and a 􀁀􀁝􀁰􀁝􀀾􀁥􀁪􀁠 method. The 􀁀􀁝􀁰􀁝􀁏􀁫􀁱􀁮􀁟􀁡 property is set to be the data returned from
an API or service, and the 􀁀􀁝􀁰􀁝􀀾􀁥􀁪􀁠 method binds the data to the control.

0 comments: