第一范文网 - 专业文章范例文档资料分享平台

ASP.net毕业论文 

来源:用户分享 时间:2025/5/16 23:05:50 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

哈尔滨工业大学毕业设计(论文)

for example, DataList1.DataBind() invokes the DataBind method on each of the controls in the DataList templates. Calling DataBind on the Page -- Page.DataBind() or simply DataBind() -- causes all data binding expressions on the page to be evaluated. DataBind is commonly called from the Page_Load event, as shown in the following example.

You can use a binding expression almost anywhere in the declarative section of an .aspx page, provided it evaluates to the expected data type at run time. The simple property, expression, and method examples above display text to the user when evaluated. In these cases, the data binding expression must evaluate to a value of type String. In the collection example, the data binding expression evaluates to a value of valid type for the DataSource property of ListBox. You might find it necessary to coerce the type of value in your binding expression to produce the desired result. For example, if count is an integer:

Number of Records: <%# count.ToString() %> Binding to Simple Properties

The ASP.NET data binding syntax supports binding to public variables, properties of the Page, and properties of other controls on the page.

The following example illustrates binding to a public variable and simple property on the page. Note that these values are initialized before DataBind() is called.

The following example illustrates binding to a property of another control. Binding to Collections and Lists

List server controls like DataGrid, ListBox and HTMLSelect use a collection as a data source. The following examples illustrate binding to usual common language runtime collection types. These controls can bind only to collections that support the IEnumerable, ICollection, or IListSource interface. Most commonly, you'll bind to ArrayList, Hashtable, DataView and DataReader.

The following example illustrates binding to an ArrayList.

The following example illustrates binding to a DataView. Note that the DataView class is defined in the System.Data namespace.

The following example illustrates binding to a Hashtable. Binding Expressions or Methods 更多精彩请登陆…

信阳人才网

http://www.xy-hr.com

哈尔滨工业大学毕业设计(论文)

Often, you'll want to manipulate data before binding to your page or a control. The following example illustrates binding to an expression and the return value of a method.

DataBinder.Eval

The ASP.NET framework supplies a static method that evaluates late-bound data binding expressions and optionally formats the result as a string. DataBinder.Eval is convenient in that it eliminates much of the explicit casting the developer must do to coerce values to the desired data type. It is particularly useful when data binding controls within a templated list, because often both the data row and the data field must be cast.

Consider the following example, where an integer will be displayed as a currency string. With the standard ASP.NET data binding syntax, you must first cast the type of the data row in order to retrieve the data field, IntegerValue. Next, this is passed as an argument to the String.Format method.

This syntax can be complex and difficult to remember. In contrast, DataBinder.Eval is simply a method with three arguments: the naming container for the data item, the data field name, and a format string. In a templated list like DataList, DataGrid, or Repeater, the naming container is always Container.DataItem. Page is another naming container that can be used with DataBinder.Eval.

The format string argument is optional. If it is omitted, DataBinder.Eval returns a value of type object, as shown in the following example.

It is important to note that DataBinder.Eval can carry a noticeable performance penalty over the standard data binding syntax because it uses late-bound reflection. Use DataBinder.Eval judiciously, especially when string formatting is not required.

Section Summary

The ASP.NET declarative data binding syntax uses the <%# %> notation. You can bind to data sources, properties of the page or another control, collections, expressions, and results returned from method calls.

List controls can bind to collections that support the ICollection, IEnumerable, or IListSource interface, such as ArrayList, Hashtable, DataView, 更多精彩请登陆…

信阳人才网

http://www.xy-hr.com

哈尔滨工业大学毕业设计(论文)

and DataReader.

DataBinder.Eval is a static method for late binding. Its syntax can be simpler than the standard data binding syntax, but performance is slower.

Section Summary

The DataList and Repeater controls provide developers fine-tuned control over the rendering of data-bound lists.

Rendering of bound data is controlled using a template, such as the HeaderTemplate, FooterTemplate, or ItemTemplate.

The Repeater control is a general-purpose iterator, and does not insert anything in its rendering that is not contained in a template.

The DataList control offers more control over the layout and style of items, and outputs its own rendering code for formatting.

The DataList supports the Select, Edit/Update/Cancel, and Item Command events, which can be handled at the page level by wiring event handlers to the DataList's Command events.

DataList supports a SelectedItemTemplate and EditItemTemplate for control over the rendering of a selected or editable item.

Controls can be programmatically retrieved from a template using the Control.FindControl method. This should be called on a DataListItem retrieved from the DataList's Items collection.

更多精彩请登陆…

信阳人才网

http://www.xy-hr.com

搜索更多关于: ASP.net毕业论文  的文档
ASP.net毕业论文 .doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c8foja0855j3blzb1bt1n_10.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top