Data Binding Web Controls to Alternate Data Sources

Implementation:

In addition to binding Web Controls to DataSets loaded by business objects, MM .NET also allows you to bind to a wide variety of sources including properties of business objects. This custom control binding uses .NET Reflection to walk the specified property values and bind/unbind Web controls from these sources.

You can bind to the following:

  • Object Properties
    You can bind to properties of objects that are members of the parent form. For example, if there is a public form variable named Order that contains a reference to the Orders business object and you want to bind a text box to the Order.OrderID property, you would use the following settings:

    BindingSource: Order
    BindingSourceMember: OrderID

    Note you can use nested object syntax. So if your object is a sub-object, reference that object in the BindingSource. For example, if you have a WizardSettings object on the form with a DataSettings sub-object, you can access the DataSettings.ConnectionString property using the following settings:

    BindingSource: WizardSettings.DataSettings
    BindingSourceMember: ConnectionString

  • DataRow
    You can also bind directly to a DataRow. For example, to access the DataRow property of a business object, you would use the following settings:

    BindingSource: Customer.DataRow
    BindingSourceMember: Descript (field name)

  • DataSet
    You can also bind to a DataSet directly by using the DataSet as the data source and providing the table name and field name as the binding property. The first row of the DataSet is bound.

    BindingSource: Customer.DataSet
    BindingSourceMember: Customers.Descript (tablename.fieldname)

  • DataTable and DataViews
    You can also bind to tables and views like DataSets. Binding is always against the first row. If you want to bind against different rows we suggest you bind against the row directly which is generally the cleanest approach. To bind a DataTable or DataView, specify the DataTable or DataView as the BindingSource object and then specify the field name as the BindingSourceMember property.

    BindingSource: CustomerTable
    BindingSourceMember: Firstname (fieldname)

  • Form Properties
    You can also bind to properties of the form itself. In this case use this or Me as the control source object.

    BindingSource: this
    BindingSourceMember: CustomErrorMessage (string property)

Limitations:

There are few limitations to this sort of binding.

  • Indexers and Enumerators
    Indexers and Enumerators are not supported. So the following doesn't work:

    Customer.DataSet.Tables["sometable"].Rows[0];

    If you want to bind to an indexed property, you need to expose that indexed property as a simple property of the form. For example, the above may be handled with a form level property called CustomerTable assigned like this:

    this.CustomerTable = this.Customer.DataSet.Tables["sometable"];

    then proceed to bind to CustomerTable. The same goes for the row or other indexer.

  • this and Me
    You should not use this or Me as a prefix to object reference except when you explicitly want to access form properties.

    The following doesn't work because the binding source should be Customer.DataRow:

    BindingSource: this.Customer.DataRow
    BindingSourceMember: Company

    The following does work:

    BindingSource: this
    BindingSourceMember: CustomErrorMessage (string property)


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 03/13/13
Comment or report problem with topic