好文档 - 专业文书写作范文服务资料分享网站

ASP.net毕业论文 

天下 分享 时间: 加入收藏 我要投稿 点赞

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

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毕业论文 

哈尔滨工业大学毕业设计(论文)forexample,DataList1.DataBind()invokestheDataBindmethodoneachofthecontrolsintheDataListtemplates.CallingDataBindonthePage--Page.DataBind()orsimplyDat
推荐度:
点击下载文档文档为doc格式
8foja0855j3blzb1bt1n
领取福利

微信扫码领取福利

微信扫码分享