2023年全國(guó)碩士研究生考試考研英語(yǔ)一試題真題(含答案詳解+作文范文)_第1頁(yè)
已閱讀1頁(yè),還剩5頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、<p>  出自 《微軟ado.net數(shù)據(jù)技術(shù)》</p><p>  The Data Binding Technology</p><p>  In my project,I need to show the data from the DataBase,so I need to use the data binding technology which Microsoft c

2、ompany support.In the following ,let's discuss it together.</p><p>  If you are familiar with classic ASP, the declarative data binding syntax introduced in ASP.NET will be familiar to you even though th

3、e 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 proper

4、ties, expressions, and results from method calls exposed by the page. While this feature is easy to use, it often causes some confusion about what is al</p><p>  Data binding basics</p><p>  Dat

5、a binding expressions link ASP.NET page properties, server control properties, and data sources when the page's DataBind method is called. You can place data binding expressions on the value side of an attribute/valu

6、e 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.</p><p>  When u

7、sed 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,

8、the same syntax may be used outside list controls. This includes displaying values on the page or populating control attributes.</p><p>  Container.DataItem is a runtime alias for the DataItem bound to a spe

9、cific 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 determined by the data source. So, if you

10、're dealing with an array of integers, the DataItem will be an integer.</p><p>  The following list provides a quick review of the VB.NET syntax for various scenarios:</p><p>  <%# Contai

11、ner.DataItem %>--An array of string values is returned. </p><p>  <%# Container.DataItem("expression") %>--The specific field from a DataView container is returned. </p><p>  

12、<%# Container.DataItem.PropertyName %>--The specific string property value of data source is returned. </p><p>  <%# CStr(Container.DataItem.PropertyName) %>--Returns a property value converted t

13、o its string representation. </p><p>  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 synt

14、ax is the same, but it changes when property values are returned and converted to the appropriate data type.</p><p>  <%# Container.DataItem %> </p><p>  <%# ((DataRowView)Container.Dat

15、aItem)["PropertyName"] %> </p><p>  <%# ((ObjectType)Container.DataItem).PropertyName %> </p><p>  <%# ((ObjectType)Container.DataItem).PropertyName.ToString() %> </p

16、><p>  Syntax is consistent when working with page level properties and methods. The syntax remains the same as long as string values are returned. The following list provides some examples:</p><p>

17、;  <%# propertyName %>--The value for a page level property is returned. </p><p>  <asp:ListBox id="lstValues" datasource='<%# propertyName %>' runat="server">--

18、The value retrieved from the page level property (array, collection of objects, etc.) is bound to the data control. </p><p>  <%# (objectName.PropertyName) %>--The value of the page level object proper

19、ty is displayed. </p><p>  <%# MethodName() %>--The value returned from the page method is displayed. </p><p>  You may use individual values (albeit properties, method return values, and

20、so forth) on a page using the following syntax:</p><p>  <%= Value %></p><p>  The C# code in Listing A demonstrates data binding in an ASP.NET Web form. It selects employee names and tele

21、phone numbers from the SQL Server Northwind Employees table. The values 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 po

22、pulated 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 befo</p><p>  Listing B contains the

23、 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.</p><p>  Using the Contain.DataItem object can

24、 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.</p><p>  Microsoft documentation (on MSD

25、N) 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

26、 binding syntax. This method can also be used declaratively on a Web form's page to simplify casting from one type to another.</p><p>  You can use the Eval method of the DataBinder class to make .NET do

27、 the heavy lifting when 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 an

28、d displays it accordingly. It has the following syntax:</p><p>  DataBinder.Eval(Container.DataItem, "field name", "optional formatting")</p><p>  Using this syntax, you coul

29、d 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.</p><p>  The DataBinder.Eval approach is great as it pushes work to th

30、e 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.</p><p>  Plenty of options</p>

31、<p>  Data binding makes it relatively simple to include data in ASP.NET pages. There are various data binding options available, which include: binding the data to a control and allowing it to decide how it is pre

32、sented, 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.</p><p><b>  數(shù)據(jù)捆綁技術(shù)</b>

33、</p><p>  在我的項(xiàng)目中,我需要從數(shù)據(jù)庫(kù)顯示數(shù)據(jù),因此我使用數(shù)據(jù)捆綁的技術(shù) 它是由微軟公司支持的。如下,我們一起來(lái)談?wù)撍?lt;/p><p>  如果你熟悉經(jīng)典ASP,在ASP.NET介紹申明數(shù)據(jù)捆綁的句法與它在功能是有很大的不同。 數(shù)據(jù)捆綁的表達(dá)方式:就是能在ASPX文件中以在此形式(< %#和% >)之間出現(xiàn)的代碼。 這種表達(dá)方式允許你把控件很容易地綁定到數(shù)據(jù)源,連

34、同屬性,語(yǔ)法,結(jié)果值同時(shí)在方法調(diào)用時(shí)在頁(yè)面中顯示。 當(dāng)這些特性輕松的被使用時(shí),由于它是否被允許能夠被調(diào)用而經(jīng)常造成一些的混亂</p><p>  數(shù)據(jù)捆綁的基本原則:</p><p>  當(dāng)DataBind方法被調(diào)用時(shí),數(shù)據(jù)就捆綁到ASP.NET的控件屬性,數(shù)據(jù)源。 數(shù)據(jù)表達(dá)式可以放置在頁(yè)面的任何一處,或置于服務(wù)器控件成對(duì)標(biāo)簽的之間的附值處。 所有數(shù)據(jù)捆綁的表達(dá)式,不論是將它們放置在哪,都

35、必須包含在< %#和% >標(biāo)志之間。</p><p>  當(dāng)數(shù)據(jù)控件(像轉(zhuǎn)發(fā)器一樣,DataGrid,如此等等)綁定時(shí),表達(dá)參數(shù)通常是數(shù)據(jù)源的一張表的一個(gè)列名。盡管如此,只要返回一個(gè)數(shù)值,這個(gè)數(shù)值表達(dá)式就被調(diào)用了。 同樣地,相同的句法可以用在列表控件之外。 這主要包括在頁(yè)面上顯示數(shù)值或者是控件的屬性值。</p><p>  Container.DataItem是專門(mén)為DataI

36、tem綁定到特殊項(xiàng)上專門(mén)設(shè)置的控件。它指向數(shù)據(jù)源處的一個(gè)數(shù)據(jù)項(xiàng)目如表中的一個(gè)數(shù)據(jù)行或者是列表中的某個(gè)元素的值。 DataItem的實(shí)際的數(shù)據(jù)類型是由數(shù)據(jù)源確定的。 因此,如果你處理一個(gè)整型數(shù)組,DataItem的數(shù)據(jù)類型則是整型。</p><p>  下面的表達(dá)式是用VB.Net來(lái)調(diào)用在各種情況下Container.DataItem的調(diào)用情況,讓我們來(lái)快速的回顧下。</p><p>  &

37、lt; %# Container.DataItem % > --串價(jià)值的一個(gè)陣列被返回。 </p><p>  < %# Container.DataItem (“表達(dá)”) % > --從一個(gè)DataView容器的具體的值被返回。 </p><p>  < %# Container.DataItem.PropertyName % > --數(shù)據(jù)源的具體的串值被返

38、回。 </p><p>  < %# CStr ( Container.DataItem.PropertyName ) % > --用被改變的一數(shù)值覆蓋其串值表達(dá)式值。 </p><p>  當(dāng)你使用C#時(shí),句法是有點(diǎn)不同的。 下列表達(dá)式則在原先的列基礎(chǔ)上每行再加上相應(yīng)的C#代碼。 注意到基本的句法同樣,但是當(dāng)數(shù)值被返回和返回值被改變成為適當(dāng)?shù)臄?shù)據(jù)類型時(shí),它就發(fā)生變化了。<

39、;/p><p>  < %# Container.DataItem % ></p><p>  < %# ( ( DataRowView ) Container.DataItem )["PropertyName" ] % ></p><p>  < %# ( ( ObjectType ) Container.DataIt

40、em ).PropertyName % ></p><p>  < %# ( ( ObjectType ) Container.DataItem ).PropertyName.ToString ( ) % ></p><p>  句法是與當(dāng)頁(yè)面的屬性和方法一致的被。當(dāng)串值被返回時(shí),語(yǔ)法結(jié)構(gòu)仍然保持不變。 如下則是提供了一些例子:</p><p> 

41、 < %# propertyName % > --一頁(yè)面屬性值被返回。 </p><p>  < asp:ListBox id="lstValues”datasource='<%# propertyName %>的runat="server" > --從頁(yè)面取回的數(shù)值(數(shù)組,對(duì)象集)綁定倒數(shù)據(jù)控件上。 </p><p&g

42、t;  < %# ( objectName.PropertyName ) % > --頁(yè)實(shí)例屬性值被顯示。 </p><p>  < %# MethodName( ) % > --調(diào)用方法時(shí)返回的值顯示。 </p><p>  你能在Page頁(yè)上使用如下句法使用特殊的的數(shù)值( 屬性值,方法返回值,等等):</p><p><b> 

43、 < %=數(shù)值% ></b></p><p>  在列表A中的C#代碼是用ASP.NET技術(shù)實(shí)現(xiàn)的數(shù)據(jù)捆綁。 它從SQL服務(wù)器Northwind雇員表中選擇雇員名稱和電話號(hào)碼。 查詢的數(shù)值是通過(guò)ASP.NET轉(zhuǎn)發(fā)器來(lái)控制顯示的。 列表數(shù)值通過(guò)數(shù)據(jù)捆綁的技術(shù)被插入,而Form的頁(yè)面數(shù)值是通過(guò)使用方法調(diào)用來(lái)實(shí)現(xiàn)數(shù)值的傳遞。此外,DataItem的ItemIndex屬性用來(lái)顯示一數(shù)字。ItemI

44、ndex屬性從零開(kāi)始,因此一但有數(shù)值顯示,它就自動(dòng)的+1</p><p>  列表B包含相等的VB.NET代碼。 主要的區(qū)別在于在C#中應(yīng)用了括號(hào)。然而,這不是VB.NET的必須執(zhí)行的。</p><p>  當(dāng)意識(shí)到使用時(shí)必須知道數(shù)據(jù)類型并且要隨著應(yīng)用而發(fā)生改變時(shí),就會(huì)覺(jué)得使用Contain.DataItem變得有些麻煩,不是很方便。因此微軟對(duì)DataBinder類作了改進(jìn),使它的應(yīng)用變得

45、相對(duì)要簡(jiǎn)單些。</p><p>  在系統(tǒng)運(yùn)行時(shí),微軟文件(在MSDN上)申明在DataBinder類中將數(shù)據(jù)綁定表達(dá)式的值的數(shù)據(jù)類型強(qiáng)制轉(zhuǎn)換成實(shí)例的數(shù)值類型。在Visual Studio .NET中,這方法讓RAD設(shè)計(jì)者很容易對(duì)數(shù)據(jù)捆綁的句法作語(yǔ)法分析。 這方法也能通過(guò)申明將一個(gè)Web的頁(yè)面類型很簡(jiǎn)單的轉(zhuǎn)換成為另一種類型。</p><p>  當(dāng)在頁(yè)面中使用數(shù)據(jù)值時(shí),DataBinder

46、類的Eval方法能起著舉足輕重的作用。 Eval方法接受以前覆蓋的Container.DataItem對(duì)象; 它根據(jù)情況改變,根據(jù)表達(dá)式推算出字段的具體細(xì)節(jié)并且將它顯示出來(lái)。它有如下句法:</p><p>  DataBinder.Eval ( Container.DataItem,“字段名”,“格式化選項(xiàng)”)</p><p>  使用這種句法結(jié)構(gòu),列表C.列表D中看起來(lái)象C#代碼,就能像

47、使用DataBinder.Eval重寫(xiě)第一個(gè)包含相同結(jié)構(gòu)的VB.NET代碼例子。</p><p>  DataBinder.Eval方法應(yīng)用到系統(tǒng)中時(shí),功能是很強(qiáng)的。 但同時(shí),當(dāng)時(shí)間和資源隨著系統(tǒng)調(diào)用元素項(xiàng)并決定調(diào)用返回?cái)?shù)據(jù)類型而慢慢耗盡時(shí),就必須謹(jǐn)慎的使用。</p><p><b>  大量的選擇</b></p><p>  數(shù)據(jù)捆綁使得調(diào)用

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論