绑定列字段和模板列字段之间的区别 [英] Difference between Bound column field and template column field
问题描述
我想主要了解asp.net gridview中的绑定列字段和模板列字段.请帮助我.
I would like to know about bound column field and template column field in asp.net gridview mainly the difference. Please help me .
推荐答案
Boundfield
是直接绑定到数据源(数据库中的列)的列.
Boundfield
is a column bound direct to the datasource (column in a DB).
< asp:TemplateField/>
是一个自定义列,可以包含这样的DB列,也可以将它们连接在一起以进行显示.
A <asp:TemplateField />
is a customized column which can contain either a DB column as such or you may join together columns for display.
使用 boundfield
仅显示db列,使用 TemplateField
进行更多操作,例如将2个db列连接为单个gridview列,或添加一些额外的文本/可能不是来自数据库的网格的描述/参数.
Use boundfield
to simply display the db column, use TemplateField
to do something more fancy such as concatenate 2 db columns as a single gridview column or add some extra text/description/para to the grid that may not come from the db.
让我们看看何时以及如何使用TemplateFields的一个基本示例.
Lets see one basic example of when and how to use TemplateFields.
我想在网格中有2列,代表数据库中的2列. FirstName
和 LastName
,因此GridView标记将具有::
I want to have 2 columns in my grid that represent 2 columns in the db.
FirstName
and LastName
so the GridView markup will have::
<asp:BoundField DataField="FirstName" />
<asp:BoundField DataField="LastName" />
但是,如果要将它们连接在一起,则需要使用模板字段":这里 eval("FirstName")
被称为数据绑定表达式.
But if you want to concatenate them together you need to use Template Fields::
Here eval("FirstName")
is called as the data binding expression.
<asp:TemplateField HeaderText="FullName" >
<ItemTemplate>
eval("FirstName") + " " + eval("LastName")
</ItemTemplate>
</asp:TemplateField>
通常,在大多数情况下,当我们需要的不仅仅是开箱即用功能时,我们会使用模板列.
Usually and most of the time , we use a template column when we need more than out of the box functionality for the column.
这篇关于绑定列字段和模板列字段之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!