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.

Unbinding handles unbinding and checking for unbinding errors for invalid data values that can't be converted back into their underlying data source. On failure of .Unbind() the BindingErrors collection will be set. A typical unbind operation occurs in button click event or other 'save' operation fired from the page:

<> protected void btnSave_Click(object sender, EventArgs e) { // unbind back into the underlying data source: Product.Entity for most fields DataBinder.Unbind();

// check for binding errors and display if there's a problem     if (DataBinder.BindingErrors.Count > 0)     {         ErrorDisplay.Text = DataBinder.BindingErrors.ToHtml();         return;     }

// validate the business object - check product entity for rule violations     if (!Product.Validate())     {         // Automatically add binding errors from bus object ValidationErrors         // requires IList that has ControlID and Message properties

DataBinder.AddValidationErrorsToBindingErrors(Product.ValidationE rrors);

    // You can also manually add binding error messages and assign to a  control         //DataBinder.AddBindingError("Invalid Country Code",txtCountry);

    ErrorDisplay.Text = DataBinder.BindingErrors.ToHtml();         return;     }

if (!Product.Save())     {         ErrorDisplay.ShowError("Couldn't save Product:
" + Product.ErrorMessage); return; } ErrorDisplay.ShowMessage("Product information has been saved."); } <
public bool Unbind(Control Container)

Return Value

True if there are no errors. False if unbinding failed. Check the BindingErrors for errors.


The top level container Control that is bound.


See also:

Class DataBinder

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