# Add Controls to Column Templates

This tutorial shows how to:

* Add controls to a **RadGrid** template column's ItemTemplate and EditItemTemplate.

* Enable the grid control for editing using automatic updates.

* Set RadGrid's skin using the Smart Tag.

* Enable paging for RadGrid and changing its page size with the design editor.

## 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 your 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 Visual Studio's 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's** [Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag), expand the drop-down list labeled **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 happen to encounter a **"Database schema could not be retrieved"** exception, please follow the guide in [this](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/visual-studio-2012-datasource-configuration) help topic.

1. On the **Configure Select Statement** page, select the Orders table from the drop-down list, select the **OrderID**, **CustomerID**, **EmployeeID**, and **OrderDate** fields, and click the **Next** button:

   ![Configure Select Statement](https://www.telerik.com/products/aspnet-ajax/documentation/assets/2f16dd214a4a260a3169e53f37e411b9/grid_add-controls-to-template6.png)

2. Click the **Specify a custom SQL statement or stored procedure** radio button.Then choose **Next**:

   ![Specify a custom SQL statement](https://www.telerik.com/products/aspnet-ajax/documentation/assets/61152b761225ae4efd06645c9d1d4866/grid_add-controls-to-template7.png)

3. Add an **Update** statement to the data source:

   ![Configure Update statement](https://www.telerik.com/products/aspnet-ajax/documentation/assets/f548752ec0e9a722c18a9af79cded480/grid_add_controls_to_template8.png)

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

   ![Test Query](https://www.telerik.com/products/aspnet-ajax/documentation/assets/c357c6cb6c964b2fd2fa2170873112df/grid_add-controls-to-template9.png)

## Adding Template columns

1. Using the RadGrid's Editor, add a template column to the grid:
   * Open **RadGrid's Configuration Wizard** from the [Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag).<br/>

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

   * Select **MasterTableView** under **RadGrid** node.

   * Select **Columns** tab 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**.<br/>

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

2. Click **Edit Templates** from the **RadGrid's** [Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag):

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

3. Choose the Template column that you wish to edit:

   ![Rad Grid grd addcontrols 03](https://www.telerik.com/products/aspnet-ajax/documentation/assets/d779004a9f5c39a042173fd0105767a8/radgrid_grd_addcontrols03.png)

4. Drag and drop a **RadDatePicker** control from Visual Studio's toolbox ontothe **EditItemTemplate**.

   ![Rad Grid grd addcontrols 04](https://www.telerik.com/products/aspnet-ajax/documentation/assets/d64f4723db68440c4bf6834cec71e789/radgrid_grd_addcontrols04jpg.png)

5. Now add a **Label** control to the **ItemTemplate**.

   ![grid addcontrols 04 1](https://www.telerik.com/products/aspnet-ajax/documentation/assets/fe1f06d17c9ad70814762693b8f5daab/grid_addcontrols04_1.png)

6. Select **Edit DataBindings** from the **RadDatePicker's Smart Tag**:

   ![Rad Grid grd addcontrols 05jpg](https://www.telerik.com/products/aspnet-ajax/documentation/assets/9465d35c8aace6160c8e58d814b3452c/radgrid_grd_addcontrols05jpg.png)

7. In the **DataBindings** dialog:
   * Check **Show all properties** to view the properties of the date picker.
   * Choose the **SelectedDate** property as the property to bind.
   * Choose the **OrderDate** field as the **Fieldbinding**.
   * Check the **Two-way data binding** box to enable the control to update the field value.<br/>
     ![Rad Grid grd addcontrols 06jpg](https://www.telerik.com/products/aspnet-ajax/documentation/assets/6994baa05b29fbe7aeebb8d6c0fc55de/radgrid_grd_addcontrols06jpg.png)

8. Use a similar technique to bind the **Label** control:

   ![Rad Grid grd addcontrols 6jpg](https://www.telerik.com/products/aspnet-ajax/documentation/assets/ceb0cec7c7a1b2265e530572e0598905/radgrid_grd_addcontrols6jpg.png)

9. Use the **RadGrid's** [Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag) to end template editing:

   ![grid addcontrols 7jpg](https://www.telerik.com/products/aspnet-ajax/documentation/assets/84f36fd68440810d3cfdba4b74de62bf/grid_addcontrols7jpg.png)

## Enabling editing, paging, and change the Skin

1. Back in **RadGrid's** Editor, add an edit command column to the grid:

   ![grid addcontrols 08jpg](https://www.telerik.com/products/aspnet-ajax/documentation/assets/24b556a9195be838182a45bf24dcbf83/grid_addcontrols08jpg.png)

2. Remove the **OrderDate** column; the Template column will be used instead:

   ![grid addcontrols 10jpg](https://www.telerik.com/products/aspnet-ajax/documentation/assets/f36e3753a9e766cbce43e72fbb03e15d/grid_addcontrols10jpg.png)

3. Still in the RadGrid's Editor check the **AllowAutomaticUpdates** checkbox on the right pane:

   ![grid addcontrols 09jpg](https://www.telerik.com/products/aspnet-ajax/documentation/assets/1dcda8ae290d8114eb140b4d448f2839/grid_addcontrols09jpg.png)

4. Now select the **MasterTableView** node, then select **Paging** tab and change the **Page size** to **5** rows.

   ![grid addcontrols 11](https://www.telerik.com/products/aspnet-ajax/documentation/assets/950b57020db2fa6251a8ba3c8dd6c478/grid_addcontrols11.png)

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

   ![grid addcontrols 12](https://www.telerik.com/products/aspnet-ajax/documentation/assets/65df1b2b491c7d8c04c69950ff826fbb/grid_addcontrols12.png)

6. Run the application. Click the edit column to see the edit template you added. Note that if you edit a value in the grid, the database is updated:

   ![GridEditing](https://www.telerik.com/products/aspnet-ajax/documentation/assets/50e863beed0e403ee7217597e325a010/grid_add-controls-to-template23.png)

## See Also

* [Using the RadGrid Smart Tag](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/smarttag)
* [Adding columns from design time](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/design-time/adding-columns-from-design-time)
