Binding to a Datasource
- 2 minutes to read
The ASPxImageSlider can be populated with item information taken from a data source that can be specified by using either of the following properties.
- ASPxDataWebControlBase.DataSource to programmatically supply a data object.
- ASPxDataWebControl.DataSourceID to define a declarative data source.
The ASPxImageSlider supports two methods of retrieving data from a specified data source. One involves manually setting the control’s specific data-related properties to data source item attribute names. The other one exploits the ASPxImageSlider ability to retrieve data automatically, given that the data source item attributes are named after the property names of an ImageSliderItem object.
Data Binding Using Mapping Properties
When the ASPxImageSlider control binds to a data source, an ImageSliderItem object is created automatically for every recognized data item. Individual item characteristics (such as text, name, image path, navigation location, and thumbnail path) are obtained from the data fields (item attributes) of the corresponding data items. The ASPxImageSlider exposes its specific data-related properties, allowing you to specify which data source fields the item information should be retrieved from. The table below lists these properties and the corresponding properties of the ImageSliderItem object.
ASPxImageSlider control data-related properties | Corresponding ImageSliderItem object properties |
---|---|
ASPxImageSlider.ImageUrlField | ImageSliderItem.ImageUrl |
ASPxImageSlider.NameField | ImageSliderItem.Name |
ASPxImageSlider.NavigateUrlField | ImageSliderItem.NavigateUrl |
ASPxImageSlider.TextField | ImageSliderItem.Text |
ASPxImageSlider.ThumbnailUrlField | ImageSliderItem.ThumbnailUrl |
Example
<dx:ASPxImageSlider ID="ASPxImageSlider1" runat="server" DataSourceID="XmlDataSource1"
ImageUrlField="Image" NameField="Id" TextField="Description">
</dx:ASPxImageSlider>
Automatic Data Binding
The ASPxImageSlider control has a built-in ability to automatically retrieve data from a data source after just one property (ASPxHierarchicalDataWebControl.DataSourceID or ASPxDataWebControlBase.DataSource) is specified.
The ASPxImageSlider can recognize the data items and retrieve some item characteristics from the data fields named in a specific way. If however, any of the data-related properties of an ASPxImageSlider control (such as ASPxImageSlider.TextField, ASPxImageSlider.ImageUrlField, etc.) have been set, then the mapping of the associated ImageSliderItem object properties will proceed according to Data Binding Using Mapping Properties.
During binding, an ASPxImageSlider control implements its automatic binding ability by retrieving item characteristics from those data fields whose names coincide with certain property names of an ImageSliderItem object. The table below lists the names of the item object properties that can be mapped during automatic binding, and the matching data field names you should use in the data source for the mapping to work.
Node properties that can be set automatically | Data field names |
---|---|
ImageSliderItem.ImageUrl | ImageUrl |
ImageSliderItem.Name | Name |
ImageSliderItem.NavigateUrl | NavigateUrl |
ImageSliderItem.Text | Text |
ImageSliderItem.ThumbnailUrl | ThumbnailUrl |