首页 > 新闻系统 > 网络编程 > Asp.Net > 文章正文

ASP.NET2.0+SQL Server2005构建多层应用(4)

2006-01-10 16:41:06 来源:CSDN 作者: 点击:

 创建逻辑层

  接下来,我们创建逻辑层,在这个例子中,逻辑层是十分简单的,只是起到说明作用。首先,我们新建一个类AuthroBiz类,并将其放在App_code文件夹中,并将类的代码修改如下:

public class AuthorsBiz
{
 public AuthorsBiz()
 {}

 public DataTable GetAuthors()
 {
  AuthorsTableAdapters.AuthorsTableAdapter authorDB = new AuthorsTableAdapters.AuthorsTableAdapter();
  return authorDB.GetAuthors();
 }
 public DataTable GetAuthorTitles(string authorID)
 {
  AuthorsTableAdapters.AuthorTitlesTableAdapter authorDB = new AuthorsTableAdapters.AuthorTitlesTableAdapter();
  return authorDB.GetTitlesByAuthor(authorID);
 }
}

  从上面的代码中,可以看到,我们刚才通过向导创建的"Authors.xsd"类型化dataset类,现在在代码中,可以通过使用AuthorsTableAdapters类来调用,其中authorDB是AuthorsTableAdapters类的实例。

  创建表示层

  在ASP.NET 2.0中,在创建表示层时,可以使用master-page技术,使得可以很方便地构建页面。Mater-page的意思是,可以首先构建出一个页面的主框架模版结构,然后在其中放置一个ContentPlaceHolder控件,在该控件中,将展现其他子页面的内容。在其他子页面中,只需要首先引用该master页面,然后再修改ContentPlaceHolder控件的内容就可以了。

  首先,在工程中新增加一个"master"类型的文件,将其命名为CommonMaster,然后输入以下代码:

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

  接下来,我们首先创建以显示作者页面的Authors.aspx页面,由于页面的框架要保持一直,因此,可以利用maser-page技术,在新建页面时,引入刚才建立的CommonMaster页面,如下图:

′??


  点ADD按钮后,出现如下图,选择刚才建立的CommonMaster页面,如下图:

′??


  再输入如下代码:

<%@ Page Language="C#" MasterPageFile="~/CommonMaster.master" %>
<asp:content id="Content1" contentplaceholderid="middleContent" runat="server">
<asp:objectdatasource runat="server" id="authorsSource" typename="AuthorsBiz" selectmethod="GetAuthors">
9 7 3 1 2 4 8 :

精彩推荐
本类热门文章

论坛美图

本周软件下载排行

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203