创建逻辑层
接下来,我们创建逻辑层,在这个例子中,逻辑层是十分简单的,只是起到说明作用。首先,我们新建一个类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页面,如下图:
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器