【正文】
Data binding expressions link page properties, server control properties, and data sources when the page39。re dealing with an array of integers, the DataItem will be an integer. The following list provides a quick review of the syntax for various scenarios: % %An array of string values is returned. % (expression) %The specific field from a DataView container is returned. % %The specific string property value of data source is returned. % CStr() %Returns a property value converted to its string representation. When you39。% propertyName %39。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 zero, so one is added before it is displayed. Listing B contains the equivalent 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 . Using the object can be tedious, since you must be aware 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 allows 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 form39。 it works hard to figure out the details of the field identified in the expression and displays it accordingly. It has the following syntax: (, field name, optional formatting) Using this syntax, you could rewrite the first example to use to look like the C code in Listing C. Listing D contains the equivalent code. The approach is great as it pushes work to the system. On the other hand, you 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 options Data binding makes it relatively simple to include data in pages. There are various data binding options available, which include: binding the data to a control and allowing it to decide how it is presented, or choosing declarative data binding to control presentation within the page. In the end, it es down to your preference, but it is great to have options. 中文一譯文: 數(shù)據(jù)捆綁技術(shù) 在我的項(xiàng)目中 , 我需要從數(shù)據(jù)庫顯示數(shù)據(jù) , 因此我使用數(shù)據(jù)捆綁的技術(shù) 它是由微軟公司支持的。 如果你熟悉經(jīng)典 ASP,在 同。 這種表達(dá)方式允許你把控件很容易地綁定到數(shù)據(jù)源,連同屬性,語法,結(jié)果值同時(shí)在方法調(diào)用時(shí)在頁面中顯示。 數(shù)據(jù)捆綁的基本原則: 當(dāng) DataBind方法被調(diào)用時(shí),數(shù)據(jù)就捆綁到 ,數(shù)據(jù)源。 所有數(shù)據(jù)捆綁的表達(dá)式,不論是將它們放置在哪,都必須包含在 %和 % 標(biāo)志之間。盡管如此,只要返回一個(gè)數(shù)值,這個(gè)數(shù)值表達(dá)式就被調(diào)用了。 這主要包括在頁面上顯示數(shù)值或者是控件的屬 性值。它指向數(shù)據(jù)源處的一個(gè)數(shù)據(jù)項(xiàng)目如表中的一個(gè)數(shù)據(jù)行或者是列表中的某個(gè)元素的值。 因此,如果你處理一個(gè)整型數(shù)組, DataItem 的數(shù)據(jù)類型則是整型。 % % 串價(jià)值的一個(gè)陣列被返回。 % % 數(shù)據(jù)源的具體的串值被返回。 當(dāng)你使用 C時(shí),句法是有點(diǎn)不同的。 注意到基本的句法同樣,但是當(dāng)數(shù)值被返回和返回 值被改變成為適當(dāng)?shù)臄?shù)據(jù)類型時(shí),它就發(fā)生變化了。當(dāng)串值被返回時(shí),語法結(jié)構(gòu)仍然保持不變。 asp: ListBox id=lstValues”datasource=39。 % ( ) % 頁實(shí)例屬性值被顯示。 你能在 Page頁上使用如下句法使用特殊的的數(shù)值 ( 屬性值,方法返回值,等等 ): %=數(shù)值 % 在列表 A 中的 C代碼是用 技術(shù)實(shí)現(xiàn)的數(shù)據(jù)捆綁。 查詢的數(shù)值是通過 轉(zhuǎn)發(fā)器來控制顯示的。此外, DataItem 的 ItemIndex 屬性用來顯示一數(shù)字。 主要的區(qū)別在于在 C中應(yīng)用了括號(hào)。 當(dāng)意識(shí)到使用時(shí)必須知道數(shù)據(jù)類型并且要隨著應(yīng)用而發(fā)生改變時(shí),就會(huì)覺得使用,不是很方便。 在系統(tǒng)運(yùn)行時(shí),微軟文件(在 MSDN 上)申明在 DataBinder 類中將數(shù)據(jù)綁定表達(dá)式的值的數(shù)據(jù)類型強(qiáng)制轉(zhuǎn)換成實(shí)例的數(shù)值類型。 這方法也能通過申明將一個(gè) Web 的頁面類型很簡(jiǎn)單的轉(zhuǎn)換成為另一種類型。 Eval方法接受以前覆蓋的 ; 它根據(jù)情況改變,根據(jù)表達(dá)式推算出字段的具體細(xì)節(jié)并且將它顯示出來。 ,功能是很強(qiáng)的。 大量的選擇 數(shù)據(jù)捆綁使得調(diào)用 頁面相關(guān)數(shù)據(jù)是變得非常的簡(jiǎn)單。但最后,還是根據(jù)具體的 情況去使用