The CMSDataGrid control displays document data in a customizable table.
- Provides a built-in data source for loading Kentico documents from the database. You do not need to write code for retrieving and binding the data.
- You can use the Visual Studio DataGrid designer to set up the appearance and behavior of the grid.
Inherits from: BasicDataGrid
Web part equivalent (portal engine):
The tutorial shows how to use the CMSDataGrid to display a table containing all products from the Products section of the sample Corporate Site (CMS.Smartphone, CMS.Laptop, CMS.Software, CMS.Ebook and CMS.Product documents):
- Create a new Web form in your web project.
- Switch to the Design tab and drag a CMSDataGrid control from the toolbox onto the form.
- Set the following properties for the CMSDataGrid:
This tells the control which document types to read and specifies the Path to the products section.
Right-click the CMSDataGrid on the form, select AutoFormat... and choose a scheme.
Right-click the CMSDataGrid again, select Show Smart Tag and then Property Builder.
The CMSDataGrid1 Properties dialog opens.
On the General tab, check Allow sorting.
- Switch to the Columns tab and uncheck Create columns automatically at run time.
- Add a new Bound Column from the Available columns list to the Selected columns list. Enter the following values into the appropriate fields:
- Header text: Name
- Data Field: SKUName
- Sort expression: SKUName
- Add another Bound column. Enter the following values in the appropriate fields:
- Header text: Price
- Data Field: SKUPrice
- Sort expression: SKUPrice
- Click OK.
- Save the web form.
- Right-click the web form in the Solution explorer and select View in Browser.
The resulting page displays a table similar to the following (depending on the chosen scheme):
You can set the following properties for the CMSDataGrid control:
Indicates whether the control automatically performs data binding during the Init event. (Inherited from BasicDataGrid)
Indicates whether the control should be hidden when no data is loaded. The default value is False. (Inherited from BasicDataGrid)
|PageSize||Sets the number of rows displayed per page.|
Indicates whether the control processes the grid sorting in the DataView instead of on the SQL level. (Inherited from BasicDataGrid)
Custom data connected to the object. (Inherited from BasicDataGrid)
Name of the transformation applied to selected items.
Enter the transformation name in format <document type code name>.<transformation name>.
Indicates if the page index resets to the first page when sorting is changed. (Inherited from BasicDataGrid)
Indicates whether the grid sorting is in ascending order. The default value is True. (Inherited from BasicDataGrid)
Gets or sets the sort field. Allows you to set the default sort field. (Inherited from BasicDataGrid)
Text shown when the control is hidden by the HideControlForZeroRows property. (Inherited from BasicDataGrid)
"No records found"
Document filtering properties
Indicates if the control checks the permissions of the user viewing the page. If the value is false (default value) no permissions are checked.
If true, the control only loads documents for which the user viewing the page has read permissions.
Specifies which document types the control loads and displays. Identify document types through their code names, separated by semicolons (;).
You can use the * wildcard as a substitute for any number of characters. For example Product.* includes the document types Product.Camera, Product.CellPhone, Product.Computer etc.
If the property is left empty, the control retrieves all document types by default. In the case of menu and navigation controls, only page (CMS.MenuItem) documents are loaded by default.
Note: If the control loads all document types (empty value), only the common data columns from the View_CMS_Tree_Joined view are available in the retrieved data. The specific fields of individual document types are not included. You need to keep this in mind when writing the code of transformations, WHERE conditions, ORDER BY expressions etc.
Indicates whether the control loads documents from the website's default culture version if the required documents are not available in the user's selected culture.
Only applies if you do not set the TreeProvider property manually.
Specifies the culture code of the documents that the control loads. If not specified, the control automatically uses the preferred culture of the user viewing the page.
Allows you to manually assign a DataSet or DataTable containing the documents that the control displays. You do not need to set this property for standard scenarios.
Indicates if the control filters out duplicated (linked) documents from the data.
Specifies the maximum number of content tree sub-levels from which the control displays documents. This number is relative, i.e. counted from the location of the page where the control is placed, not from the root of the website.
Enter -1 to load all child documents.
Path of the documents that the control loads.
If enabled, the control only loads published documents.
Gets or sets the TreeProvider object used by the control to access document data. If you do not assign a TreeProvider object, the control automatically creates a new instance.
Document relationship properties
If set, the control only loads documents that are related to the document with the specified NodeGUID. You can find the Node GUID of documents on the Properties -> General tab in the Pages application.
Enter "11111111-1111-1111-1111-111111111111" to dynamically load documents related to the current document.
Determines whether the document specified through the RelationshipWithNodeGUID property is on the left or right side of the relationship.
Specifies the type of the document relationship. Enter the code name of the relationship.
CMS Base control properties
List of the cache keys on which the control's cached data depends. When the specified cache items change, the control clears its cache.
Each item (dependency) must be on one line.
If you leave this property empty, the control uses default dependencies.
Sets the name of the cache key used to store the control's content. If you leave the value empty, the system generates a default name containing variables, such as the control ID, the selected culture and the name of the user who loaded the page.
The system cache is shared by all pages in your application, so cache item names representing different data must be unique globally. If you have multiple controls that load the same data, you can share the cache keys between the controls (optimizes loading of content and avoids redundant data in the cache).
If the content displayed by the control depends on variables, such as URL parameters, you can set a custom name dynamically in the page's code behind.
Sets the number of minutes for which the control caches content retrieved from the database.
Allows you to set up caching of content so that the control doesn't have to retrieve content from the database on each request.
The caching mechanism uses absolute expiration time. This means that cache items expire after a specified time period even if the page containing the control wasn't requested.
Gets or sets the filter control used to limit the data read by the control.
Gets or sets the code name of the filter control used to limit the data read by this control.
Gets or sets the ORDER BY clause of the SQL query that the control uses to load data.
Database table columns that the control loads for documents, separated by commas ( , ). If null or empty, the control loads all available columns.
Specifies the code name of the Kentico website for which the control loads data.
If true, the control stops all processing — does not load or display any data or other HTML output.
Specifies the maximum number of database records that the control loads.
Gets or sets the WHERE clause of the SQL query that the control uses to loads data.
"ProductPrice > 100"
Note: The CMSDataGrid is derived from the ASP.NET DataGrid control, so you can also set any of the base properties.
Appearance and styling
You can modify the appearance of the CMSDataGrid control by setting the standard properties available for the ASP.NET DataGrid control (inherited through the BasicDataGrid).
A common way to set the appearance of DataGrid controls is to assign a skin through the SkinID property. You can define skins in .skin files under individual themes in the App_Themes folder. See the .NET Skins and Themes documentation for more information.