亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ASP.NET2.0+SQL Server2005構(gòu)建多層應(yīng)用

 更新時(shí)間:2006年12月11日 00:00:00   作者:  

  創(chuàng)建表示層

  在ASP.NET 2.0中,在創(chuàng)建表示層時(shí),可以使用master-page技術(shù),使得可以很方便地構(gòu)建頁(yè)面。Mater-page的意思是,可以首先構(gòu)建出一個(gè)頁(yè)面的主框架模版結(jié)構(gòu),然后在其中放置一個(gè)ContentPlaceHolder控件,在該控件中,將展現(xiàn)其他子頁(yè)面的內(nèi)容。在其他子頁(yè)面中,只需要首先引用該master頁(yè)面,然后再修改ContentPlaceHolder控件的內(nèi)容就可以了。

  首先,在工程中新增加一個(gè)"master"類型的文件,將其命名為CommonMaster,然后輸入以下代碼:


<%@ master language="C#" %>
<html>
?。糷ead id="Head1" runat="server">
 ?。紅itle>Master Page</title>
 </head>
<body>
<form id="Form1" runat="server">
?。紅able id="header" style="WIDTH: 100%; HEIGHT: 80px" cellspacing="1" cellpadding="1" border="1">
 <tr>
 ?。紅d style="TEXT-ALIGN: center; width: 100%; height: 74px;" bgcolor="teal">
  ?。糰sp:label runat="server" id="Header" Font-Size="12pt" Font-Bold="True">
     Authors Information
   </asp:label>
  </td>
?。?tr>
 </table>
?。糱/>
?。紅able id="leftNav" style="WIDTH: 108px; HEIGHT: 100%" cellspacing="1" cellpadding="1" border="1">
 <tr>
 ?。紅d style="WIDTH: 100px">
  ?。紅able>
   ?。紅r>
    ?。紅d>
     ?。糰 href="Home.aspx">Home</a>
     </td>
   ?。?tr>
    <tr>
    ?。紅d>
      <a href="Authors.aspx">Authors List</a>
    ?。?td>
    </tr>
  ?。?table>
  </td>
?。?tr>
?。?table>
?。紅able id="mainBody" style="LEFT: 120px; VERTICAL-ALIGN: top; WIDTH: 848px; POSITION: absolute; TOP: 94px; HEIGHT: 100%" border="1">
 ?。紅r>
  ?。紅d width="100%" style="VERTICAL-ALIGN: top">
   ?。糰sp:contentplaceholder id="middleContent" runat="Server"></asp:contentplaceholder>
  ?。?td>
  </tr>
?。?table>
</form>
</body>
</html>



接下來(lái),我們首先創(chuàng)建以顯示作者頁(yè)面的Authors.aspx頁(yè)面,由于頁(yè)面的框架要保持一直,因此,可以利用maser-page技術(shù),在新建頁(yè)面時(shí),引入剛才建立的CommonMaster頁(yè)面,如下圖:



點(diǎn)ADD按鈕后,出現(xiàn)如下圖,選擇剛才建立的CommonMaster頁(yè)面,如下圖:





再輸入如下代碼:


<%@ Page Language="C#" MasterPageFile="~/CommonMaster.master" %>
<asp:content id="Content1" contentplaceholderid="middleContent" runat="server">
<asp:objectdatasource runat="server" id="authorsSource" typename="Author*iz" selectmethod="GetAuthors">
</asp:objectdatasource>
<asp:gridview runat="server" AutoGenerateColumns="false" id="authorsView" datasourceid="authorsSource">
?。糰lternatingrowstyle backcolor="Silver"></alternatingrowstyle>
<Columns>
<asp:HyperLinkField DataTextField="au_id" HeaderText="Author ID" DataNavigateUrlFields="au_id"
DataNavigateUrlFormatString="AuthorTitles.aspx?AuthorID={0}">
</asp:HyperLinkField>
<asp:BoundField HeaderText="Last Name" DataField="au_lname"></asp:BoundField>
<asp:BoundField HeaderText="First Name" DataField="au_fname"></asp:BoundField>
<asp:BoundField HeaderText="Phone" DataField="phone"></asp:BoundField>
<asp:BoundField HeaderText="Address" DataField="address"></asp:BoundField>
<asp:BoundField HeaderText="City" DataField="city"></asp:BoundField>
<asp:BoundField HeaderText="State" DataField="state"></asp:BoundField>
<asp:BoundField HeaderText="Zip" DataField="zip"></asp:BoundField>

</Columns>
</asp:gridview>
</asp:content>


注意,其中我們用到了objectdatasource控件,在.NET 2.0中,有了該控件,可以很方便地溝通表示層和邏輯層。其中的代碼如下:


<asp:objectdatasource runat="server" id="authorsSource" typename="Author*iz" selectmethod="GetAuthors">
</asp:objectdatasource>


  其中的typename屬性指定為我們之前創(chuàng)建的邏輯層的類Author*iz類,而為了獲得數(shù)據(jù),采用了selectmethod方法,這里指定了之前建立的GetAuthors方法。當(dāng)然,也可以在其他場(chǎng)合,應(yīng)用Updatemethod,Insertmethod,Deletemethod方法,也可以加上參數(shù),比如接下來(lái)要?jiǎng)?chuàng)建的AuthorTitle.aspx頁(yè)面,代碼如下:

<%@ Page Language="C#" MasterPageFile="~/CommonMaster.master" %>
<asp:content id="Content1" contentplaceholderid="middleContent" runat="server">
<asp:objectdatasource runat="server" id="authorTitlesSource" typename="Author*iz" selectmethod="GetAuthorTitles">
<SelectParameters>
?。糰sp:QueryStringParameter Type="String" Direction="Input" Name="authorID" QueryStringField="AuthorID" />
</SelectParameters>
</asp:objectdatasource>
<asp:gridview runat="server" id="authorTitlesView" datasourceid="authorTitlesSource">
?。糰lternatingrowstyle backcolor="Silver"></alternatingrowstyle>
</asp:gridview>
</asp:content>


  上面的代碼中,首先用戶在authors.aspx頁(yè)面點(diǎn)選某個(gè)作者名時(shí),則在authortitle.aspx頁(yè)面中,返回該作者的所有著作。所以,在objectdatasource控件中,我們使用了SelectParameters參數(shù),指定傳入來(lái)要查詢的參數(shù)是authorid。最后,再將gridview綁定到objectdatasource控件中去。

  最后,運(yùn)行我們的代碼,結(jié)果如下兩圖所表示:






小結(jié)

  在ASP.NET 2.0中,我們利用SQL Server 2005的強(qiáng)大功能,可以利用.NET 語(yǔ)言創(chuàng)建存儲(chǔ)過(guò)程,并使用TableAdapter向?qū)?,很方便地?chuàng)建數(shù)據(jù)訪問(wèn)層,再利用objectdatasource控件的特性,可以很方便地溝通表示層和邏輯層。 [/sell]

相關(guān)文章

  • .Net行為型設(shè)計(jì)模式之職責(zé)鏈模式(Chain of Responsibility)

    .Net行為型設(shè)計(jì)模式之職責(zé)鏈模式(Chain of Responsibility)

    這篇文章介紹了.Net行為型設(shè)計(jì)模式之職責(zé)鏈模式(Chain of Responsibility),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • ASP.NET web.config 配置節(jié)點(diǎn)詳解

    ASP.NET web.config 配置節(jié)點(diǎn)詳解

    這篇文章主要介紹了ASP.NET web.config 節(jié)點(diǎn)的配置,講解的非常詳細(xì),需要的朋友可以參考下。
    2016-06-06
  • c#對(duì)xml的簡(jiǎn)單操作

    c#對(duì)xml的簡(jiǎn)單操作

    c#對(duì)xml的簡(jiǎn)單操作...
    2006-08-08
  • ASP.NET 中的Application詳解

    ASP.NET 中的Application詳解

    Application對(duì)象是HttpApplicationState類的一個(gè)實(shí)例,Application狀態(tài)是整個(gè)應(yīng)用程序全局的。本文主要詳細(xì)介紹Application對(duì)象的用法。
    2016-04-04
  • ASP.NET Core中的環(huán)境配置

    ASP.NET Core中的環(huán)境配置

    這篇文章介紹了ASP.NET Core中的環(huán)境配置,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • .Net設(shè)計(jì)模式之單例模式(Singleton)

    .Net設(shè)計(jì)模式之單例模式(Singleton)

    這篇文章介紹了.Net設(shè)計(jì)模式之單例模式(Singleton),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • .Net性能測(cè)試框架Crank的使用方法

    .Net性能測(cè)試框架Crank的使用方法

    這篇文章介紹了.Net性能測(cè)試框架Crank的使用方法。對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-11-11
  • .Net?Core微服務(wù)rpc框架GRPC通信實(shí)際運(yùn)用

    .Net?Core微服務(wù)rpc框架GRPC通信實(shí)際運(yùn)用

    這篇文章介紹了.Net?Core微服務(wù)rpc框架GRPC通信實(shí)際運(yùn)用,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-01-01
  • ASP.NET實(shí)現(xiàn)word文檔在線預(yù)覽功能代碼

    ASP.NET實(shí)現(xiàn)word文檔在線預(yù)覽功能代碼

    文檔管理系統(tǒng)需要實(shí)現(xiàn)WORD能在線預(yù)覽功能,以前覺(jué)得挺難的,經(jīng)過(guò)一番研究發(fā)現(xiàn),WORD自帶的另存為可以保存為HTMl文件。
    2010-07-07
  • Asp.Net常用函數(shù)

    Asp.Net常用函數(shù)

    Asp.Net常用函數(shù)...
    2007-03-03

最新評(píng)論