Data binding example - Description

Because all MForm repeated items implement the IDataItemContainer interface, it is possible to get the Xml node associated with the item, with the use of XPath and XPathSelect methods.

Using the <%# XPath("xpathExpression") %> or <%# XPathSelect("xpathExpression") %> inside the Content property of MForm controls, XML data of the current navigator context can be retrieved.

In the following example, the office data is presented. The Payment element of the Person element is not displayed with the use of MForm. Instead, a databound gridview is created.

Notice, that all this functionality was created without the use of a single line in code-behind.

The data binding syntax for XML data is rendered on the server side, so if you change data that was used in the binding on client side, the rendered data bound text will not get modified. If you for example change the first name of surname of a user, the title "Payment of {FirstName} {Surname}" will not change.

Also special care should be taken, when using this functionality with items that can be added. The added elements template will have no databound XML data during generation, so nothing is rendered in the places of using those script tags. Press "Add person" and you will see the effects.

 
Office
Office
Person
First Name
Surname
Sex
Position
Payment of Adam Badam
Type Date Value
salary 2008-10 3200
salary 2008-11 3300
bonus 2008-12 3200
Person
First Name
Surname
Sex
Position
Payment of Anna Wanna
Type Date Value
salary 2008-10 3700
bonus 2008-11 3600
bonus 2008-12 3900
Address
Street
House Number
City
Post Code