# Getting Started with RadGrid for ASP.NET AJAX

This tutorial will walk you through creating a Web page that contains a **RadGrid** control. It shows how to:

* Bind the grid using a declarative data source.
* Configure the grid to support the most common features including:
  * Paging
  * Sorting
  * Scrolling
  * Grouping
  * Filtering
  * Selecting
* Add a template column for customized data display.

## Creating and Binding the Grid

1. Locate the "..\Live Demos\App_Data" folder underneath the folder where you have installed your controls. In this folder, find the **Northwind.mdf** file, and copy it into the **App_Data** folder of your Web application. The **Solution Explorer** for you application should look something like the following:

   ![grid gettingstarted 1](https://www.telerik.com/products/aspnet-ajax/documentation/assets/6d9eb63dcf4bf25ec7bc813ab598b09a/grid_gettingstarted1.png)

2. Drag and drop a **RadGrid** control from the toolbox onto your Web page:

   ![grid gettingstarted 2](https://www.telerik.com/products/aspnet-ajax/documentation/assets/83f915d5db8425f3951314dfedba9d1c/grid_gettingstarted2.jpg)

3. Using the **RadGrid** [Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag) expand the drop-down list labelled Choose Data Source and select **\<New data source...>**:

   ![grid gettingstarted 03](https://www.telerik.com/products/aspnet-ajax/documentation/assets/47a3804d3838c51d289296bf8e3497dd/grid_gettingstarted03.jpg)

4. The **Data Source Configuration Wizard** appears. On the **Choose a Data Source Type** page, select **SQL Database** and click **OK**:

   ![grid gettingstarted 4](https://www.telerik.com/products/aspnet-ajax/documentation/assets/28ec90d2bef22ec3fb828ac9afe4d068/grid_gettingstarted4.png)

5. On the **Choose Your Data Connection** page, expand the drop-down list by clicking the little triangle on the right side and select the **Northwind.mdf** from the available options. Then click the **Next** button:

   ![grid gettingstarted 5](https://www.telerik.com/products/aspnet-ajax/documentation/assets/78aedcf367985110b6b21365ae3e2e84/grid_gettingstarted5.png)

   > note If you encounter a "Database schema could not be retrieved" exception, follow the [Visual Studio 2012 data source configuration guide](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/visual-studio-2012-datasource-configuration).

6. On the **Configure the Select Statement** page, select the Customers table from the drop-down list, select the CompanyName, ContactName, Address, and PostalCode fields. Then choose **Next**:

   ![grid gettingstarted 6](https://www.telerik.com/products/aspnet-ajax/documentation/assets/2c6c8120c1c5581f525167b53232b4ed/grid_gettingstarted6.png)

7. On the **Test Query** page, click the **Test Query** button to see the data. Then click **Finish** to exit the **Configure Data Source** wizard:

   ![grid gettingstarted 7](https://www.telerik.com/products/aspnet-ajax/documentation/assets/8e12c8575d4bc5dea749b2b512f2fc80/grid_gettingstarted7.png)

## Configuring the grid for paging, sorting, and scrolling

1. From the **Skin** drop-down of the **RadGrid's** [Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag) choose the **Metro** skin:

   ![grid gettingstarted 8](https://www.telerik.com/products/aspnet-ajax/documentation/assets/d636961f35db3aaf51f2edcd046d72db/grid_gettingstarted8.jpg)

2. In the **General Features** section, check the boxes to enable **paging**, **sorting**, and **scrolling**:

   ![grid gettingstarted 9](https://www.telerik.com/products/aspnet-ajax/documentation/assets/83bf709a5fc4d3ca251c3947a11aa590/grid_gettingstarted9.png)

3. Still in the **Smart Tag** click the link labeled **Open Editor**:

   ![grid gettingstarted 10](https://www.telerik.com/products/aspnet-ajax/documentation/assets/682d7d6cd233a9c1148d47ae38d22c28/grid_gettingstarted10.jpg)

4. In the **RadGrid** [Editor](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/setting-radgrid):
   * Select **RadGrid** from the **Configuration Manager**.
   * On the right side, click **Styles** tab. Then select **RadGrid style**.
   * In the **Layout** section of the RadGrid's style editor, locate the **Width** property and set it to **720px**:<br/>

     ![grid gettingstarted 11](https://www.telerik.com/products/aspnet-ajax/documentation/assets/4e042940dde16bbe84ba56b49b29781b/grid_gettingstarted11.png)

5. On the same window, just one tab above the **Styles** tab select **Paging tab**. Then on the right pane, set the **Page size** to **30** rows.

   ![grid gettingstarted 12](https://www.telerik.com/products/aspnet-ajax/documentation/assets/eb5af4b9540f630cf90da69df6a13ee0/grid_gettingstarted12.png)

6. Run the application to check out what you have created so far. Note the pager elements in the grid footer and the scroll bar on the right side. When you click on column headers the column data will be sorted:

   ![grid gettingstarted 13](https://www.telerik.com/products/aspnet-ajax/documentation/assets/d0a7de0211dd252881cde3e0c44459eb/grid_gettingstarted13.jpg)

## Configuring the grid for selecting, filtering, and grouping

1. Add a select column:
   * Open the **Editor**.
   * Select **MasterTableView** under **RadGrid** node.
   * Select **Columns** from the right pane.
   * Select **Button** column under **Available columns**.
   * Click the **"+"** button to add the button column.
   * Use the up arrow button to move it to the first position.
   * You need to customize the column a bit in order to work as a select column.
     * Set values to the **HeaderText**, **Text**, and **CommandName** properties.

       ![grid gettingstarted 14 1](https://www.telerik.com/products/aspnet-ajax/documentation/assets/d6113e1f55cf226b04ad9665aee4e086/grid_gettingstarted14_1.png)
     * Additionally, you could change the **UniqueName** and **BackColor** of the column.

       ![grid gettingstarted 14 2](https://www.telerik.com/products/aspnet-ajax/documentation/assets/616b57db5f922f5a90ab6c0dfc4861a4/grid_gettingstarted14_2.png)

2. Use the **RadGrid** [Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag) to enable **filtering** and **grouping**:

   ![grid gettingstarted 15JPG](https://www.telerik.com/products/aspnet-ajax/documentation/assets/5d63ea5cf7dd205bcd0bf05e9b4ba62f/grid_gettingstarted15jpg.png)

3. Run the application to see the result of your changes. A select column appears as the first column of the grid. Each column now has a filter control at the top. A grouping panel appears at the top of the grid. Drag the header of the **PostalCode** column onto the grouping panel. The rows of the grid are now grouped by postal code, and an item for this group appears in the grouping panel that lets you change the sort order of the groups:

   ![grid gettingstarted 16](https://www.telerik.com/products/aspnet-ajax/documentation/assets/522b204f9feecb3d128279a76990ae5a/grid_gettingstarted16.jpg)

## Adding Template columns

1. Back in the Editor, add a template column to the grid:
   * Select **MasterTableView** under **RadGrid** node.
   * Select **Columns** from the right pane.
   * Select **Template** column under **Available columns**.
   * Click the **"+"** button to add the template column.
   * In the right pane, set the **HeaderText** property to **TemplateColumn**.

     ![grid gettingstarted 17](https://www.telerik.com/products/aspnet-ajax/documentation/assets/3608d7f9bfdb7d99640f72e5d6bd8e91/grid_gettingstarted17.jpg)

2. In the [Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag) select **Edit Templates** option:

   ![grid gettingstarted 18](https://www.telerik.com/products/aspnet-ajax/documentation/assets/f83829d346c1f408421cfb2b4372f640/grid_gettingstarted18.png)

3. In the drop-down list of the **Smart Tag** in Template Editing Mode, select the template column to bring up the template design surface for the template column:

   ![grid gettingstarted 19](https://www.telerik.com/products/aspnet-ajax/documentation/assets/d779004a9f5c39a042173fd0105767a8/grid_gettingstarted19.png)

4. Add a **Label** to the item template and a **TextBox** to its edit item template, using drag and drop from the Visual Studio toolbox. From the **Smart Tag** of the **Label** and of the **TextBox**, choose **Edit DataBindings** to display the DataBindings editor:

   ![grid gettingstarted 20](https://www.telerik.com/products/aspnet-ajax/documentation/assets/520687f17559acdcca9392628b051059/grid_gettingstarted20.png)

5. In the DataBindings editor for the **Label** and for the **TextBox**, bind the **Text** property to a field in the datasource:

   ![grid gettingstarted 21](https://www.telerik.com/products/aspnet-ajax/documentation/assets/3008cbc3ce3a4f91f32ecf47c7066d8e/grid_gettingstarted21.png)

   ![grid gettingstarted 22](https://www.telerik.com/products/aspnet-ajax/documentation/assets/002df618b2ab959cd09fbc2e0b13207b/grid_gettingstarted22.png)

6. Now, you have a fully functional **RadGrid** with no code behind. Paging, sorting, filtering, scrolling and grouping are enabled. There is a column for server-side selection and a template column for specific data display:

   ![grid gettingstarted 23](https://www.telerik.com/products/aspnet-ajax/documentation/assets/7502138048f8bee8dd1751c17ff457b6/grid_gettingstarted23.jpg)

## See Also

* [Using the RadGrid Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag)
* [Setting RadGrid properties](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/setting-radgrid)
