BoundField vs TemplateField (Gridview)

What are the difference between BoundField and TemplateField?
When should you use one over the other?
LVL 8
JRockFLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

QPRCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
QPRCommented:
example.

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" >
                     <ItemTemplate>
                        eval("FirstName") + " " + eval("surname")
                    </ItemTemplate>
                </asp:TemplateField>

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
0
JRockFLAuthor Commented:
Thank you for the detailed explanation, that really helps.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.