外文翻译---数据捆绑技术_第1页
外文翻译---数据捆绑技术_第2页
外文翻译---数据捆绑技术_第3页
外文翻译---数据捆绑技术_第4页
外文翻译---数据捆绑技术_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.附 录1英文原文The Data Binding TechnologyIn my project,I need to show the data from the DataBase,so I need to use the data binding technology which Microsoft company support.In the following ,let's discuss it together.If you are familiar with classic ASP, the declarative data binding syntax introduce

2、d in ASP.NET will be familiar to you even though the functionality is vastly different. Data binding expressions are the code you see between <%# and %> characters in an ASPX file. The expressions allow you to easily bind controls to data sources, as well as properties, expressions, and result

3、s from method calls exposed by the page. While this feature is easy to use, it often causes some confusion about what is allowed and whether it should be employed.Data binding basicsData binding expressions link ASP.NET page properties, server control properties, and data sources when the page's

4、 DataBind method is called. You can place data binding expressions on the value side of an attribute/value pair in the opening tag of a server control or anywhere in the page. All data binding expressions, regardless of where you place them, must be contained between <%# and %> characters.When

5、 used with data controls (like Repeater, DataGrid, and so forth), the expression parameter is usually a column name from the data source. However, as long as it returns a value, any valid expression may be used. Likewise, the same syntax may be used outside list controls. This includes displaying va

6、lues on the page or populating control attributes.Container.DataItem is a runtime alias for the DataItem bound to a specific item. It maps to an individual item from the data source like one row from a database query or an individual element from an array. The actual data type for the DataItem is de

7、termined by the data source. So, if you're dealing with an array of integers, the DataItem will be an integer.The following list provides a quick review of the VB.NET syntax for various scenarios:<%# Container.DataItem %>-An array of string values is returned. <%# Container.DataItem(&qu

8、ot;expression") %>-The specific field from a DataView container is returned. <%# Container.DataItem.PropertyName %>-The specific string property value of data source is returned. <%# CStr(Container.DataItem.PropertyName) %>-Returns a property value converted to its string represe

9、ntation. When you're using C#, the syntax is a bit different. The following list includes the corresponding C# code for each line in the previous list. Notice the basic syntax is the same, but it changes when property values are returned and converted to the appropriate data type.<%# Containe

10、r.DataItem %> <%# (DataRowView)Container.DataItem)"PropertyName" %> <%# (ObjectType)Container.DataItem).PropertyName %> <%# (ObjectType)Container.DataItem).PropertyName.ToString() %> Syntax is consistent when working with page level properties and methods. The syntax r

11、emains the same as long as string values are returned. The following list provides some examples:<%# propertyName %>-The value for a page level property is returned. <asp:ListBox id="lstValues" datasource='<%# propertyName %>' runat="server">-The value r

12、etrieved from the page level property (array, collection of objects, etc.) is bound to the data control. <%# (objectName.PropertyName) %>-The value of the page level object property is displayed. <%# MethodName() %>-The value returned from the page method is displayed. You may use indivi

13、dual values (albeit properties, method return values, and so forth) on a page using the following syntax:<%= Value %>The C# code in Listing A demonstrates data binding in an ASP.NET Web form. It selects employee names and telephone numbers from the SQL Server Northwind Employees table. The val

14、ues from the query are displayed via an ASP.NET Repeater control. The column values are inserted via data binding, and the form's window title is populated using a method call. In addition, the ItemIndex property of the DataItem is used to display a row number. The ItemIndex property begins with

15、 zero, so one is added before it is displayed.Listing B contains the equivalent VB.NET code. The main difference is the use of parentheses as opposed to brackets in C#. Also, the casting of the rows is not necessary with VB.NET.Using the Contain.DataItem object can be tedious, since you must be awar

16、e of the data type and convert it accordingly for use. Microsoft does provide the DataBinder class to further simplify development.Microsoft documentation (on MSDN) states the DataBinder class uses reflection to parse and evaluate a data binding expression against an object at runtime. This method a

17、llows RAD designers, such as Visual Studio .NET, to easily generate and parse data binding syntax. This method can also be used declaratively on a Web form's page to simplify casting from one type to another.You can use the Eval method of the DataBinder class to make .NET do the heavy lifting wh

18、en using data values in an ASP.NET page. The Eval method accepts the previously covered Container.DataItem object; it works hard to figure out the details of the field identified in the expression and displays it accordingly. It has the following syntax:DataBinder.Eval(Container.DataItem, "fiel

19、d name", "optional formatting")Using this syntax, you could rewrite the first example to use DataBinder.Eval to look like the C# code in Listing C. Listing D contains the equivalent VB.NET code.The DataBinder.Eval approach is great as it pushes work to the system. On the other hand, y

20、ou should use it with caution, since time and resources are consumed as the system locates the element and determines its object/data type.Plenty of optionsData binding makes it relatively simple to include data in ASP.NET pages. There are various data binding options available, which include: bindi

21、ng the data to a control and allowing it to decide how it is presented, or choosing declarative data binding to control presentation within the ASP.NET page. In the end, it comes down to your preference, but it is great to have options.附 录2中文译文数据捆绑技术 在我的项目中,我需要从数据库显示数据,因此我使用数据捆绑的技术 它是由微软公司支持的。如下,我们一

22、起来谈论它。 如果你熟悉经典ASP,在ASP.NET介绍申明数据捆绑的句法与它在功能是有很大的不同。 数据捆绑的表达方式:就是能在ASPX文件中以在此形式(< %#和% >)之间出现的代码。 这种表达方式允许你把控件很容易地绑定到数据源,连同属性,语法,结果值同时在方法调用时在页面中显示。 当这些特性轻松的被使用时,由于它是否被允许能够被调用而经常造成一些的混乱。数据捆绑的基本原则:当DataBind方法被调用时,数据就捆绑到ASP.NET的控件属性,数据源。 数据表达式可以放置在页面的任何一处,或置于服务器控件成对标签的之间的附值处。 所有数据捆绑的表达式,不论是将它们放置在哪,

23、都必须包含在< %#和% >标志之间。当数据控件(像转发器一样,DataGrid,如此等等)绑定时,表达参数通常是数据源的一张表的一个列名。尽管如此,只要返回一个数值,这个数值表达式就被调用了。 同样地,相同的句法可以用在列表控件之外。 这主要包括在页面上显示数值或者是控件的属性值。Container.DataItem是专门为DataItem绑定到特殊项上专门设置的控件。它指向数据源处的一个数据项目如表中的一个数据行或者是列表中的某个元素的值。 DataItem的实际的数据类型是由数据源确定的。 因此,如果你处理一个整型数组,DataItem的数据类型则是整型。下面的表达式是用VB

24、.Net来调用在各种情况下Container.DataItem的调用情况,让我们来快速的回顾下。< %# Container.DataItem % > -串价值的一个阵列被返回。 < %# Container.DataItem (“表达”) % > -从一个DataView容器的具体的值被返回。 < %# Container.DataItem.PropertyName % > -数据源的具体的串值被返回。 < %# CStr ( Container.DataItem.PropertyName ) % > -用被改变的一数值覆盖其串值表达式值。 当

25、你使用C#时,句法是有点不同的。 下列表达式则在原先的列基础上每行再加上相应的C#代码。 注意到基本的句法同样,但是当数值被返回和返回值被改变成为适当的数据类型时,它就发生变化了。< %# Container.DataItem % >< %# ( ( DataRowView ) Container.DataItem )"PropertyName" % >< %# ( ( ObjectType ) Container.DataItem ).PropertyName % >< %# ( ( ObjectType ) Container.

26、DataItem ).PropertyName.ToString ( ) % >句法是与当页面的属性和方法一致的被。当串值被返回时,语法结构仍然保持不变。 如下则是提供了一些例子:< %# propertyName % > -一页面属性值被返回。 < asp:ListBox id="lstValues”datasource='<%# propertyName %>的runat="server" > -从页面取回的数值(数组,对象集)绑定倒数据控件上。 < %# ( objectName.PropertyName ) % > -页实例属性值被显示。 < %# MethodName( ) % > -调用方法时返回的值显示。 你能在Page页上使用如下句法使用特殊的的数值( 属性值,方法返回值,等等):< %=数值% >在列表A中的C#代码是用ASP.NET技术实现的数据捆绑。 它从SQL服务器Northwind雇员

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论