New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Declarative Data Source

You can bind a RadImageGallery to any ASP.NET declarative data source control, including SqlDataSource, AccessDataSource, ObjectDataSource, XmlDataSource, EntityDataSource, OpenAccessDataSource, LinqDataSource and ObjectContainerDataSource.

The steps below demonstrate how to bind a RadImageGallery to a SqlDataSource. The sample assumes that you have installed the Telerik sample database. If you have not done that, there is an article here describing how to install a sample database.

  1. Add a SqlDataSource control to a page and set its SelectCommand appropriately.

  2. Place a RadImageGallery control on the page.

  3. Assign the DataSourceID property to the data source control ID from step 1.

  4. Set the DataImageField property to the name of the data source field containing the images.

In addition, you could set different optional properties:

  • DataTitleField: Specifies the field with the title for each image. If not specified, images would have no Title.

  • DataDescriptionField: Specifies the field containing the description for each image. If not specified, images would have no Description.

  • DataThumbnailField: Specifies the field containing the thumbnail for each image. If this property is not set, thumbnails will be generated automatically.

Example 1: Binding a RadImageGallery to a SqlDataSource

<telerik:RadImageGallery RenderMode="Lightweight" runat="server" ID="RadImageGallery2" DataSourceID="SqlDataSource1" DataDescriptionField="Description" DataImageField="ImageUrl"
    DataTitleField="Title">
</telerik:RadImageGallery>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" 
    ProviderName="System.Data.SqlClient" SelectCommand="SELECT [ImageUrl], [Description], [Title] FROM [CityImages]"></asp:SqlDataSource>

See Also

In this article