Username:   Remember Me
Password:  

Uber Articles {Über (ger) adj. above, beyond }

- Above and Beyond a Mere Article Directory

 
 

Using Template Fields With The ASP.NET GridView Control

By Nathan Albright

In ASP.NET, placing a GridView control on your page is one of the simplest ways of displaying databound data. The GridView can be created simply by opening the Database Explorer and dragging the table or view that from which you want to display information. However, the default GridView which is automatically generated in this way almost always needs some tweaking. One typical change you may want to make is to change some of the BoundFields elements to TemplateFields elements.

The BoundField object displays data from a given column in the data source with no real modification. By contrast, any content you desire can be placed inside a TemplateField element. This makes it ideal for setting up validation through the use of validation controls.

TemplateFields offer great flexibility by allowing you to include a variety of templates to cater for the different states of the conditions arising within the GridView. There are several types of template which may be added inside a TemplateField object; the main ones are described below.

Use the HeaderTemplate to customize the information which will be displayed in the header of the column in which the TemplateField is located.

The ItemTemplate is used to display the information which you want displayed for each row of data when the GridView object is not selected for editing.

The EditItemTemplate is used to display the information which you want displayed for each row of data when the GridView object is in edit mode. It is here that you would place the controls necessary for validation.

Most of the time, information currently held in the database is displayed by adding a TextBox control inside the EditItemTemplate and databind it to the appropriate column from the data source using a statement like Bind(“FirstName”). Inside the same EditItemTemplate, you would then place the necessary validation control. For example, if you want to ensure that the field is not left blank when the form is submitted, you would insert a RequiredFieldValidator control.

You can find out more about ASP.NET training courses, visit Macresource Computer Training, an independent computer training company offering ASP.NET Classes in London and throughout the UK.

categories: asp.net,web development,web design,internet,computers,software

Article kindly provided by UberArticles.com

Topics: Computers and Technology | Comments Off

Tags: , , , , , ,


Article Citation
MLA Style Citation:
Albright, Nathan . "Using Template Fields With The ASP.NET GridView Control." Using Template Fields With The ASP.NET GridView Control. 22 Jun. 2010. uberarticles.com. 23 Dec 2014 <http://uberarticles.com/computers-and-technology/asp-nets-gridview-control-becomes-even-more-flexible-with-template-fields/>.

APA Style Citation:
Albright, N (2010, June 22). Using Template Fields With The ASP.NET GridView Control. Retrieved December 23, 2014, from http://uberarticles.com/computers-and-technology/asp-nets-gridview-control-becomes-even-more-flexible-with-template-fields/

Chicago Style Citation:
Albright, Nathan . "Using Template Fields With The ASP.NET GridView Control" uberarticles.com. http://uberarticles.com/computers-and-technology/asp-nets-gridview-control-becomes-even-more-flexible-with-template-fields/


Reprint Rights

Creative Commons License
This article is subject to a revocable license under a Creative Commons Attribution-No Derivative Works 3.0 Unported License, which means you may freely reprint it, in its entirety, provided you include the author's resource box along with LIVE VISIBLE links (without "nofollow" tags). We may revoke the license at any time with or without cause. You must also include the credit to UberArticles.com.

Comments are closed.

Disclaimer
Uber Articles and its partner sites cannot be held responsible for either the content nor the originality of any articles. If you believe the article has been stolen from you without your permission, please contact us and we will remove it immediately. If you have a problem with the accuracy or otherwise of the content of an article, please contact the author, not us! Also, please remember that any opinions and ideas presented in any of the articles are those of the author and cannot be taken to represent the opinions of Uber Articles. All articles are provided for informational purposes only. None of them should be relied upon for medical, psychological, financial, legal, or other professional advice. If you need professional advice, see a professional. We cannot be held responsible for any use or misuse you make of the articles, nor can we be held responsible for any claims for earnings, cures, or other results that the article might make.
  • RSS Feed

    RSS for Computers and Technology