1 右击网站——>添加新项——>选择母版页——>父级母版页中代码
1
<%
@ Master Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeBehind
=
"
ParentMaster.master.cs
"
Inherits
=
"
WebZZ.ParentMaster
"
%>
2
3 <! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
4
5 < html xmlns = " http://www.w3.org/1999/xhtml " >
6 < head runat = " server " >
7 < title > 无标题页 </ title >
8 < asp:ContentPlaceHolder ID = " head " runat = " server " >
9 </ asp:ContentPlaceHolder >
10 </ head >
11 < body >
12 < form id = " form1 " runat = " server " >
13 < div id = " banner1 " style = " text-align:center " >
14 < img src = " 1.png " width = " 750px " height = " 150px " alt = " banner graphic " />
15 </ div >
16 < div >
17 < asp:ContentPlaceHolder ID = " ContentPlaceHolder1 " runat = " server " >
18
19 </ asp:ContentPlaceHolder >
20 </ div >
21 < div id = " banner2 " style = " text-align:center " >
22 < img src = " 2.png " alt = " footer graphic " width = " 750px " height = " 50px " />
23 </ div >
24 </ form >
25 </ body >
26 </ html >
2
3 <! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
4
5 < html xmlns = " http://www.w3.org/1999/xhtml " >
6 < head runat = " server " >
7 < title > 无标题页 </ title >
8 < asp:ContentPlaceHolder ID = " head " runat = " server " >
9 </ asp:ContentPlaceHolder >
10 </ head >
11 < body >
12 < form id = " form1 " runat = " server " >
13 < div id = " banner1 " style = " text-align:center " >
14 < img src = " 1.png " width = " 750px " height = " 150px " alt = " banner graphic " />
15 </ div >
16 < div >
17 < asp:ContentPlaceHolder ID = " ContentPlaceHolder1 " runat = " server " >
18
19 </ asp:ContentPlaceHolder >
20 </ div >
21 < div id = " banner2 " style = " text-align:center " >
22 < img src = " 2.png " alt = " footer graphic " width = " 750px " height = " 50px " />
23 </ div >
24 </ form >
25 </ body >
26 </ html >
2 右击网站——>添加新项——>选择嵌套母版页——>子级母版页中代码
<%@ Master Language="C#" MasterPageFile="~/ParentMaster.Master" AutoEventWireup="true" CodeBehind="ChildMaster.master.cs" Inherits="WebZZ.ChildMaster" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="divleft" style="width:200px; height:400px;">
<asp:ContentPlaceHolder ID="leftcolumn" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="divright" style="width:650px; height:400px; float:right; margin:-400px 200px;">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</div>
</asp:Content>
3 右击网站——>添加新项——>选择web 内容窗体——>(只有为母版页添加了内容项才能运行浏览母版嵌套效果)
<%@ Page Language="C#" MasterPageFile="~/ChildMaster.master" AutoEventWireup="true" CodeBehind="BisiManager.aspx.cs" Inherits="WebZZ.BisiManager" Title="无标题页" %>
<asp:Content ID="Content1" ContentPlaceHolderID="leftcolumn" runat="server">
<!-- treeview是BisiManager中的一个树形结构-->
<asp:TreeView ID="TreeView1" runat="server" ShowLines="True">
</asp:TreeView>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!--绑定数据控件-->
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None" PageSize="5" Width="488px">
<PagerSettings Mode="NumericFirstLast" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="empid" HeaderText="ID" />
<asp:BoundField DataField="empnam" HeaderText="名称" />
<asp:BoundField DataField="birthday" HeaderText="出生年月" />
<asp:BoundField DataField="xuid" HeaderText="序号" />
<asp:BoundField DataField="role" HeaderText="角色" />
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
一个母版嵌套的简单实例完成