Tip # 53: Did you know... How to edit the templates for gridview in VS designer?

Gridview control has the flexibility to be configured how it's rendered using templates. Following steps show how the control's edit template can be changed in the Visual Studio Designer.

  • I have a GridView hooked up to Sqldatasource using Northwind.products. I have selected Generate Insert, update and delete statements while configuring the sql data source (by clicking the Advanced button)

    image 

    image 

  • Click on smart task for grid view & select Enable Editing check box for the grid view

    image

  • Now to convert a column to use Template field. Select Edit columns from the Grid view Smarttask.

    image

  • Select the column name in the selected fields list and click on Convert this field into TemplateField & click OK

     image

  • Select Edit Templates from the gridview smarttask

    image 

  • From the Display drop down select EditItemTemplate

    image 

  • You will see the following

    image

  • You can update the template now. For example, I have dragged dropped requireFiledValidator into it

    image

  • If there are multiple columns converted to templates, you will see something like this & can select a particular column template to be edited.

    image

  • Switching to the source view, you will find that VS has generated the source code for the template changes done.

    image

  • Click on 'End template editing' from the smart task to exit editing the template

    image

 

Deepak Verma
SDET | Visual Web Developer