在Asp.net中数据控件中模板的用途是什么?以及如何在数据控件中使用模板? [英] What is the use of template in data controls in Asp.net ? And How to use template in data controls ?

查看:52
本文介绍了在Asp.net中数据控件中模板的用途是什么?以及如何在数据控件中使用模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道数据控件用于显示来自各种数据源的数据但是模板的用途是什么?

for ex in Data grid view control?

解决方案



GridView 组成 a set 字段,指示数据源包含 输出沿 数据的显示方式。最简单的字段 type BoundField,它显示数据值 as text 。其他字段类型使用备用HTML元素显示数据。 CheckBoxField, 示例,将呈现为 a check 框,其检查状态取决于 指定的数据字段; ImageField呈现图像,其图像 来源 基于指定的数据字段。超链接按钮的状态取决于 基础数据字段值可以呈现分别使用 HyperLinkField ButtonField字段类型。
CheckBoxField,ImageField,HyperLinkField, ButtonField字段类型允许 视图 数据,它们仍然相当有限 尊重 格式。 CheckBoxField只能显示一个检查框,而ImageField只能显示一个图像。什么如果特定字段必须显示 some text 检查框, 图像所有基于不同的数据字段值? 如果我们希望 显示data 使用除CheckBox之外的Web控件,图像,HyperLink,按钮?此外,BoundField将其显示限制为单个数据字段。 如果我们希望 显示两个单个GridView列中的更多数据字段

适应 灵活性,GridView提供TemplateField,使用
模板呈现。模板可以包含混合 静态HTML,Web控件,数据绑定语法。此外,TemplateField有各种模板,可以使用 自定义渲染用于不同的情况。 对于示例,ItemTemplate 使用 默认 每行呈现单元格 ,但编辑数据时,可以使用EditItemTemplate模板 自定义接口





  参考 这些 网址: 
http: // msdn.microsoft.com/en-us/library/bb288032.aspx
http: // www.maconstateit .NET /教程/ aspnet20 / ASP NET07 / aspnet07-05.aspx
http: // www.asp.net/web-forms/tutorials/data-access/custom-formatting/using-templatefields-in-the-gridview-control-cs
http: // msdn.microsoft.com/en-us/库/ bb288032.aspx


I know data controls are used for displaying data from various data source but then what is the use of template ?
for ex in Data grid view control ?

解决方案

Hi,

   The GridView is composed of a set of fields that indicate what properties from the DataSource are to be included in the rendered output along with how the data will be displayed. The simplest field type is the BoundField, which displays a data value as text. Other field types display the data using alternate HTML elements. The CheckBoxField, for example, renders as a check box whose checked state depends on the value of a specified data field; the ImageField renders an image whose image source is based upon a specified data field. Hyperlinks and buttons whose state depends on an underlying data-field value can be rendered using the HyperLinkField and ButtonField field types, respectively.
While the CheckBoxField, ImageField, HyperLinkField, and ButtonField field types allow for an alternate view of the data, they still are fairly limited with respect to formatting. A CheckBoxField can only display a single check box, whereas an ImageField can display only a single image. What if a particular field must display some text, a check box, and an image, all based upon different data-field values? Or what if we wanted to display the data using a Web control other than the CheckBox, Image, HyperLink, or Button? Furthermore, the BoundField limits its display to a single data field. What if we wanted to show two or more data-field values in a single GridView column?

To accommodate this level of flexibility, the GridView offers the TemplateField, which renders using a template. A template can include a mix of static HTML, Web controls, and data-binding syntax. Furthermore, the TemplateField has a variety of templates that can be used to customize the rendering for different situations. For example, the ItemTemplate is used by default to render the cell for each row, but the EditItemTemplate template can be used to customize the interface when editing data.



please refer these urls:
http://msdn.microsoft.com/en-us/library/bb288032.aspx
http://www.maconstateit.net/tutorials/aspnet20/ASPNET07/aspnet07-05.aspx
http://www.asp.net/web-forms/tutorials/data-access/custom-formatting/using-templatefields-in-the-gridview-control-cs
http://msdn.microsoft.com/en-us/library/bb288032.aspx


这篇关于在Asp.net中数据控件中模板的用途是什么?以及如何在数据控件中使用模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆