欢迎光临
我们一直在努力

ASP.NET2.0+SQL Server2005构建多层应用(4)-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

创建逻辑层

  接下来,我们创建逻辑层,在这个例子中,逻辑层是十分简单的,只是起到说明作用。首先,我们新建一个类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页面,如下图:

′??
赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.NET2.0+SQL Server2005构建多层应用(4)-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章