绑定列字段和模板列字段之间的区别

编程入门 行业动态 更新时间:2024-10-28 18:25:51
本文介绍了绑定列字段和模板列字段之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想主要了解asp gridview中的绑定列字段和模板列字段.请帮助我.

I would like to know about bound column field and template column field in asp 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.

更多推荐

绑定列字段和模板列字段之间的区别

本文发布于:2023-07-16 23:12:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126911.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   绑定   区别   模板

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!