Introduction to the DataRepeater Control (Visual Studio)

The Visual Basic Power Packs DataRepeater control is a scrollable container for controls that display repeated data, for example, rows in a database table. It can be used as an alternative to the DataGridView control when you need more control over the layout of the data. The DataRepeater "repeats" a group of related controls by creating multiple instances in a scrolling view. This enables users to view several records at the same time.

For a related video demonstration, see How Do I: Use the DataRepeater Control?

Overview

At design time, the DataRepeater control consists of two sections. The outer section is the viewport, where the scrolling data will be displayed at run time. The inner (top) section, known as the item template, is where you position controls that will be repeated at run time, typically one control for each field in the data source. The properties and controls in the item template are encapsulated in the ItemTemplate property.

At run time, the ItemTemplate is copied to a virtual DataRepeaterItem object that is used to display the data when each record is scrolled into view. You can customize the display of individual records in the DrawItem event, for example, highlighting a field based on the value that it contains. For more information, see How to: Change the Appearance of a DataRepeater Control (Visual Studio).

The most common use for a DataRepeater control is to display data from a database table or other bound data source. In addition to ADO.NET data objects, the DataRepeater control can bind to any class that implements the IList interface (including arrays), any class that implements the IListSource interface, any class that implements the IBindingList interface, or any class that implements the IBindingListView interface.

Data Binding

Typically, you accomplish data binding by dragging fields from the Data Sources window onto the DataRepeater control. For more information, see How to: Display Bound Data in a DataRepeater Control (Visual Studio).

When working with large amounts of data, you can set the VirtualMode property to True to display a subset of the available data. Virtual mode requires the implementation of a data cache from which the DataRepeater is populated, and you must control all interactions with the data cache at run time. For more information, see Virtual Mode in the DataRepeater Control (Visual Studio).

You can also display unbound controls on a DataRepeater control. For example, you can display an image that is repeated on each item. For more information, see How to: Display Unbound Data in a DataRepeater Control (Visual Studio).

Events

The most important events for the DataRepeater control are the DrawItem event, which is raised when new items are scrolled into view, and the CurrentItemIndexChanged event, which is raised when an item is selected. You can use the DrawItem event to change the appearance of the item. For example, you can highlight negative values. Use the CurrentItemIndexChanged event to access the values of controls when an item is selected.

The DataRepeater control exposes all the standard control events in the Code Editor. However, some of the events should not be used. Keyboard and mouse events such as KeyDown, Click, and MouseDown will not be raised at run time because the DataRepeater control itself never has focus.

The DataRepeaterItem does not expose events at design time because it is created only at run time. If you want to handle keyboard and mouse events, you can add a Panel control to the ItemTemplate at design time and then handle the events for the Panel. For more information, see Troubleshooting the DataRepeater Control (Visual Studio).

Customizations

There are many ways to customize the appearance and behavior of the DataRepeater control, both at run time and at design time. Properties can be set to change colors, hide or modify the item headers, change the orientation from vertical to horizontal, and much more. For more information, see How to: Change the Appearance of a DataRepeater Control (Visual Studio), How to: Display Item Headers in a DataRepeater Control (Visual Studio), and How to: Change the Layout of a DataRepeater Control (Visual Studio).

Note that some properties apply to the DataRepeater control itself whereas others apply only to the ItemTemplate. Make sure that you have the correct section of the control selected before you set properties. For more information, see How to: Change the Appearance of a DataRepeater Control (Visual Studio).

Other customizations include controlling the ability to add or delete records, adding search capabilities, and displaying related data in a master and detail format. For more information, see How to: Disable Adding and Deleting DataRepeater Items (Visual Studio), How to: Search Data in a DataRepeater Control (Visual Studio), and How to: Create a Master/Detail Form by Using Two DataRepeater Controls (Visual Studio).

See Also

Tasks

Walkthrough: Displaying Data in a DataRepeater Control (Visual Studio)

Troubleshooting the DataRepeater Control (Visual Studio)

Other Resources

DataRepeater Control

Change History

Date

History

Reason

July 2008

Added topic.

SP1 feature change.