BoundField vs TemplateField (Gridview)

What are the difference between BoundField and TemplateField?
When should you use one over the other?
Who is Participating?
QPRConnect With a Mentor Commented:
Boundfield is a column bound direct to a datasource (column in a DB)
A template field is a home made column (so to speak) which can contain either a DB column or whatever you like.

Use boundfield to simply display the db column, use template to do something more fancy such as concatonate 2 db columns as 1 gridview column or add some text to the grid that doesn't come from the db
QPRConnect With a Mentor Commented:

I want to have 2 columns in my grid that represent 2 columns in my db.
First name and surname so I have....
<asp:BoundField DataField="FirstName"  />
<asp:BoundField DataField="SurName"  />'

But if you want to string them together you could have....

 <asp:TemplateField HeaderText="Name" >
                        eval("FirstName") + " " + eval("surname")

so basically you convert a bound field to a template column when you want more than out of the box functionality for the column.
Template columns also come with a edittemplate tag which offers you more than the standard editing of that gridview row is desired... e.g when in edit mode put a drop down list in this row for me to select from - possibilities are endless
JRockFLAuthor Commented:
Thank you for the detailed explanation, that really helps.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.