BasicDataGrid

The BasicDataGrid control is inherited from the standard ASP.NET DataGrid control. It automatically ensures data binding, paging and sorting. You can use the standard DataGrid designer to set up BasicDataGrid style and behavior.

 

BasicDataGrid can be used with any bindable data source - it doesn't use Kentico CMS database or API.

 

See also: CMSDataGrid.

 

Properties

 

Property Name

Description

Sample Value

DataBindByDefault

Indicates whether data binding should be performed by default.

 

HideControlForZeroRows

Hides the control when no data is loaded. Default value is False.

 

ProcessSorting

Indicates if sorting should be processed in DataView instead of sorting on the SQL level.

 

SortAscending

Direction of sorting. Default value is True.

 

SortField

Gets or sets the sort field. It can be used for setting the default sort field.

"NewsReleaseDate"

ZeroRowsText

Text to be shown when control is hidden by HideControlForZeroRows.

"No records found"

SetFirstPageAfterSortChange

Indicates if the current page should be set to the first page when the sorting is changed.


 

Design

 

The design can be modified in the same way as the standard DataGrid control.

 

Example

 

This example will show you how to read the list of products and display it in the grid.

 

1.Create a new Web form.
2.Drag and drop the BasicDataGrid control on the form.
3.In the Properties window, click Auto Format... and choose some color schema.
4.In the Properties window, click Property Builder..., the BasicDataGrid1 Properties dialog appears.
- On the General tab, check the "Allow sorting" box.
- Now we will specify the columns that will be displayed. On the Columns tab:
  - Uncheck the Create columns automatically at run time box.
  - Add a new Bound Column from the Available columns list to the Selected columns list. Enter the following values in the appropriate fields:
     - Header text: Name
     - Data field: ProductName
     - Sort expression: ProductName
  - Add another Bound Column from the Available columns list to the Selected columns list. Enter the following values in the appropriate fields:
     - Header text: Price
     - Data field: ProductPrice
     - Sort expression: ProductPrice

- On the Paging tab check the box Allow Paging. Click OK.

 

5.Add the following code at the beginning of the Web form code-behind:

 

[C#]

 

using CMS.CMSHelper;

 

[VB.NET]

 

Imports CMS.CMSHelper

 

What you did

You have included namespaces we will use.

 

6.Add the following code to the Page_Load method:

 

[C#]

 

DataSet ds = TreeHelper.SelectNodes("/%", false, "CMS.Product", "", "ProductName", -1, true);

BasicDataGrid1.DataSource = ds;

BasicDataGrid1.DataBind();

 

[VB.NET]

  

Dim ds As DataSet = TreeHelper.SelectNodes("/%", False, "CMS.Product", "", "ProductName", -1, true)

BasicDataGrid1.DataSource = ds

BasicDataGrid1.DataBind()

 

What you did

You have added code that reads data from the database and provides them to the BasicDataGrid control.

 

7.Compile and run the project. You should see a page like this:

 

clip0004