Basic DataBinding


 Sample Home | Reset Form | New Developer
Please select a developer: (list binding)




Company:  
Name:  
Address:  
City:  
State:
Country:
Updated:


This sample is a little more involved and demonstrates two way databinding of simple controls like textboxes as well as list based binding.

This page contains several list controls that are bound using list-binding bound to cursors. The page also contains a number of textboxes that are bound using ControlSource Binding. ControlSource binding provides two way binding support to any expression FoxPro supports. In this example, we're binding to a SCATTER NAME object. The form loads the requested record, does a scatter name and then calls this.DataBind() to bind all the controls to their control-source. On saving the process is reversed by calling UnbindData() to retrieve the data back into the ControlSource.

The sample also demonstrates automatic error handling in case of Unbinding() errors, which highlight affected controls. You can also explictly assign errors to controls using this.Page.AddBindingError(). The BindingErrors Collection can also be assigned to html and then displayed in an ErrorDisplay control which provides summary error info, and the ability to jump to the control(s) that have errors.

Please note that this sample, bind to data using a SCATTER NAME object rather than binding directly to database fields. Although you can bind to fields of a database directly, this is not recommended as unbinding will then bind directly back to the database tables before having validated the data. This means if there's an error you'd have to undo the changes either manually or by using table buffering and TABLEUPDATE(). It's your choice, but I generally prefer using SCATTER NAME as it provides a more logical model in this environment. In fact, the wwBusiness object uses a similar approach and the full Step by Step Walk Through uses the wwBusiness class for its examples.