Class DataBinder

The DataBinder class provides two-way, simple databinding a single datasource value and single control property. It can bind object properties and fields and database values (DataRow fields) to a control property such as the Text, Checked or SelectedValue properties. In a nutshell the controls acts as a connector between a datasource and the control and provides explicit databinding for the control.

The control supports two-way binding. Control can be bound to the datasource values and can be unbound by taking control values and storing them back into the datasource. The process is performed explicitly by calling the DataBind() and Unbind() methods of the control. Controls attached to the databinder can also be bound individually.

The control also provides a BindErrors collection which captures any binding errors and allows friendly display of these binding errors using the ToHtml() method. BindingErrors can be manually added and so application level errors can be handled the same way as binding errors. It's also possible to pull in ASP.NET Validator control errors.

Simple validation is available with IsRequired for each DataBinding item. Additional validation can be performed server side by implementing the ValidateControl event which allows you to write application level validation code.

This control is implemented as an Extender control that extends any Control based class. This means you can databind to ANY control class and its properties with this component.

public class DataBinder : Control, IExtenderProvider

Class Members




Fires immediately after the control has been bound. You can check for errors or perform additional validation.


Fires immediately after binding is complete. You can check for errors and take additional action.


Fired just before the control is bound. You can return false from the handler to cause the control to not be bound


Fires immediately before unbinding of a control takes place. You can return false to abort DataUnbinding.


Event that can be hooked to validate each control after it's been unbound. Allows for doing application level validation of the data once it's been returned.



Adds a binding to the control. This method is a simple way to establish a binding.

public DataBindingItem AddBinding(Control ControlToBind,     string ControlPropertyToBind,     object SourceObjectToBindTo,     string SourceMemberToBindTo)

public DataBindingItem AddBinding(Control ControlToBind,     string ControlPropertyToBind,     string SourceObjectNameToBindTo,     string SourceMemberToBindTo)

public DataBindingItem AddBinding(Control ControlToBind)


Adds a binding error message to a specific control attached to this binder BindingErrors collection.

public bool AddBindingError(string ErrorMessage,     string ControlName)

public bool AddBindingError(string ErrorMessage,     Control Control)

public bool AddBindingError(string ErrorMessage,     DataBindingItem BindingItem)


Takes a collection of ValidationErrors and assigns it to the matching controls. The IList object should have Message and ControlID (optional) properties.

public void AddValidationErrorsToBindingErrors(IList errors)


Determines whether a control can be extended. Basically we allow ANYTHING to be extended so all controls except the databinder itself are extendable.

public sealed bool CanExtend(object extendee)


Performs data binding against each of the defined DataBindingItems defined on the DataBinder control. This binds all BindingSources to the specified control properties.

public bool DataBind()

public bool DataBind(Control Container)


Returns a specific DataBinding Item for a given control. Always returns an item even if the Control is not found. If you need to check whether this is a valid item check the BindingSource property for being blank.

public DataBindingItem GetDataBindingItem(Control control)

public DataBindingItem GetDataBindingItem(string ControlId)


Picks up all controls on the form that implement the IDataBinder interface and adds them to the DataBindingItems Collection

public void LoadFromControls(Control Container)


Fires the BeforeUnbindControl event

public bool OnBeforeUnbindControl(DataBindingItem Item)


Fires the ValidateControlEvent

public bool OnValidateControl(DataBindingItem Item)


Unbinds value from controls back into their underlying binding sources for the defined DataBinding items of this control. Returns true on success false on failure.

public bool Unbind()

public bool Unbind(Control Container)


Automatically imports all controls on the form that implement the IDataBinder interface and adds them to the DataBinder


Binding Error message when a control fails to bind


A collection of binding errors that is filled after binding or unbinding if errors occur during binding and unbinding.


A collection of all the DataBindingItems that are to be bound. Each <DataBindingItem> contains the information needed to bind and unbind a DataSource to a Control property.


A default binding source that is used if the binding source on an individual item is not set.


Optional Url to the Warning and Info Icons. Note: Used only if the control uses images.


Hides the Validator display and uses only the DataBinder's display for errors


Determines whether this control works as an Extender object to other controls on the form. In some situations it might be useful to disable the extender functionality such as when all databinding is driven through code or when using the IDataBinder interface with custom designed controls that have their own DataBinder objects.


Message displayed when IsRequired is blank.


Determines whether binding errors are display on controls.


Error displayed when an unbinding error occurs. Typically this will be some sort of format conversion problem {0} denotes the derived field name.


Determines whether the control uses client script to inject error notification icons/messages into the page. Setting this flag to true causes JavaScript to be added to the page to create the messages. If false, the DataBinder uses Controls.Add to add controls to the Page or other Containers.


Namespace: Westwind.Web.Controls
Assembly: westwind.web.webforms.dll

See also:

Databinding with DataBinder

© West Wind Technologies, 1996-2016 • Updated: 12/12/15
Comment or report problem with topic