The Basics of Templates in Server Controls
page 1 of 6
Published: 02 Feb 2004
Unedited - Community Contributed
What do the Repeater, the DataGrid and the DataList controls all have in common? The answer is that they have “Templates”. Justin Lovell will demonstrate and explain the basics of creating templates for your server controls.
by Justin Lovell
Average Rating: 
Views (Total / Last 10 Days): 33734/ 100


First Article – The Basics of Building Server Controls
Second Article – Reusing and Creating Server Controls

Third Article - Building Composite Server Controls (previous article)


Download the source that is demonstrated in this article.


At a stage in your development of server controls, you will need to understand how templates work under server controls. Templates are not only restricted for use for server controls but can be used for any control that will appear on the page.


Templates are generally used in data-bounded controls. However, it would be necessary for an introduction first. This article will demonstrate:


  • A simple output from a server control with a template.
  • Create a template which will modify the output of any data-bounded control.


This article will also assume that you are familiar with the template controls like the Repeater and the DataList controls.

View Entire Article

User Comments

Title: Mr   
Name: Graham J
Date: 2007-02-10 2:10:59 PM
Thanks Justin, the MSDN class details regarding FormView and Item Template's didn't really delve into creating the control within C# alone. Plus I couldn't establish how to bind a textbox to my datasource for an insert. I decided to scour the net to see what scraps of information I could find. But when I found this page, I saw I wouldn't have to look any futher - you've answered all my questions in one place. Thank you much-o!
Title: question on adding templates   
Name: Peter Kellner
Date: 2006-08-12 12:22:37 PM
I'm a little confused. I added your downloaded controls to my project, dragged in the SimpleTemplateControl to my design surface, and I expected to see a template automatically created. It was not. What am I not understanding?

Thanks, for a great article.

Title: love this   
Name: cyberguest
Date: 2006-02-21 10:28:30 AM
thanks, great article with simple, easy to understand examples
Title: Missing VB code   
Name: JP
Date: 2005-08-03 4:27:50 AM
What happened to showing VB code as was done in previous articles ?
Title: Excellent   
Name: Muhammed YAseen
Date: 2005-07-05 9:24:59 AM
I forgot to go the next page there i found how to add childcontrols at runtime
Title: Excellent   
Name: Muhammed YAseen
Date: 2005-07-05 9:23:44 AM
This is an excellent way of adding controls in a container control. Can we do this at runtime? I mean adding child controls at runtime.
Title: Thanks   
Name: DC
Date: 2005-03-20 5:59:19 PM
Thanks Justin, as usual your article are very helpfull.
Can't wait for the next article ;-)
Title: Excellent   
Name: Reng van Oord
Date: 2004-08-27 4:14:09 AM
I'm learning a lot reading these articles. Thanks a lot!

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-28 5:53:57 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search