JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Complex Data Binding

As with a number of Windows controls, some Web server controls support complex data binding, such as the Web server data grid control (other such controls include list boxes, checkbox lists, data lists, and so on). In complex binding, a control can display multiple fields at once, as in a data grid, which can display an entire table. Here are the properties you use to support complex data binding in Web applications (not all complex-bound controls will support all these properties):

  • DataSource—Gets/sets the source of a list of data values.

  • DataMember—Gets/sets the data member in a data source to bind to.

  • DataKeyField—Gets/sets the primary key field in the data source assigned to the DataSource property.

  • DataTextField—Gets/sets the field name from a data source to bind to.

  • DataTextFormatString—Gets/sets the string that specifies a data display format.

  • DataValue—Gets/sets the data field to use for the value of each list item, much like the ValueMember property in Windows controls.

Note that you use the DataTextFormatString property to create a custom display format for data. The data format string consists of two parts, separated by a colon, in the form {X:Ynn}. The value before the colon (X here) specifies the parameter index in a zero-based list of parameters (currently, this should always be 0), the character after the colon (Y here) specifies the format to display the value in, and nn specifies format options. Here are the possible formats for the Y parameter:

  • C— Uses currency format.

  • D— Uses decimal format.

  • E— Uses scientific (exponential) format.

  • F— Uses fixed format.

  • G— Uses general format.

  • N— Uses number format.

  • X— Uses hexadecimal format.

For example, the formatting string {0:D4} formats a data item with four decimal places.

That's how things look in overview—now let's take a look at a full data-binding example to get us started.

Tip 

Even with complex-bound controls, you also can use the (DataBindings) property in addition to those listed here to bind every property of the control to a data source.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor