母版页和子页面设置

时间:2013-08-20 13:24:43

标签: c# asp.net vb.net gridview master-pages

我想创建一个包含工具栏(添加,编辑,删除,批准,取消批准)以及gridview的母版页,如下所示。这个母版页将有很多孩子。我想重用gridview和工具栏......而不是将它们都添加到我创建的每个页面中。

<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="JSPSite.master.vb" Inherits="SSPayroll.JSPSite" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/Style1.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="Form1" runat="server">
    <div class="page">
        <div class="header">
            <div class="title">

            <h1>
                <asp:Image ID="Image1" runat="server" ImageUrl="~/images/GSCV1.01 - Copy.png" 
                    Height="73px" style="margin-top: 20px" Width="428px" />
            </h1>
            </div>

            <div class="loginDisplay">
                <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                    <LoggedInTemplate>
                        <asp:Label ID="Label2" runat="server" Text="User: " Font-Names="Cambria"></asp:Label><span class="bold">
                            <asp:LoginName ID="HeadLoginName" runat="server" Font-Names="Cambria" />
                        </span> [
                        <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect"
                            LogoutPageUrl="~/" Font-Names="Cambria" Font-Size="Small" ForeColor="#D9D5D5" Font-Bold="True" LogoutText="Sign Out" />
                        ]
                                            <div>

                </div>
                    </LoggedInTemplate>
                    <RoleGroups>
                        <asp:RoleGroup>
                        </asp:RoleGroup>
                    </RoleGroups>
                </asp:LoginView>   
                <asp:Label ID="Label1" runat="server" Text="Date/Time" Font-Names="Cambria" 
                        Font-Size="Small" ForeColor="#333333"></asp:Label>            
             </div>

            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="False"
                    IncludeStyleBlock="False" Orientation="Horizontal" BackColor="#FFFBD6" 
                    DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" 
                    ForeColor="#990000" StaticSubMenuIndent="10px" Enabled="True">
                    <DynamicHoverStyle BackColor="#990000" ForeColor="White" />
                    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                    <DynamicMenuStyle BackColor="#FFFBD6" />
                    <DynamicSelectedStyle BackColor="#FFCC66" />
                    <Items>
                                            <asp:MenuItem  Text="Menu1" Value="Tools">
                                                <asp:MenuItem NavigateUrl="~/JSPayroll/Payment_Rules/PaymentRules.aspx" Text="Payment Rules" Value="Payment Rules"></asp:MenuItem>
                        </asp:MenuItem>

                    </Items>
                    <StaticHoverStyle BackColor="#990000" ForeColor="White" />
                    <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                    <StaticSelectedStyle BackColor="#FFCC66" />
                </asp:Menu>
            </div>  
        </div> 
        <asp:ContentPlaceHolder ID="ToolBarPlaceHolder" runat="server" >
           <asp:Panel ID="Panel1" runat="server" HorizontalAlign="Center">
              <div>
                <hr />
                <asp:ImageButton ID="ImageButton1" runat="server" Height="48px" ImageUrl="~/IconsPack/Home.png" Width="48px" ToolTip="Home" CssClass="morph" PostBackUrl="~/JSPayroll/JSPDefault.aspx"/>
                <asp:ImageButton ID="ImageButton2" runat="server" Height="48px" ImageUrl="~/IconsPack/Add.png" PostBackUrl="~/JSPayroll/Payment_Rules/PaymentRulesDetails.aspx" ToolTip="Add Record" CssClass="morph" Width="48px"/>
                <asp:ImageButton ID="ImageButton3" runat="server" Height="48px" ImageUrl="~/IconsPack/Edit E.png" ToolTip="Edit Record" CssClass="morph" Width="48px" />
                <asp:ImageButton ID="ImageButton4" runat="server" Height="48px" ImageUrl="~/IconsPack/ViewDetails.png" ToolTip="View Record Details" CssClass="morph" Width="48px" />
                <asp:ImageButton ID="ImageButton5" runat="server" Height="48px" ImageUrl="~/IconsPack/Delete.png" ToolTip="Delete Record" CssClass="morph" Width="48px" />
                <asp:ImageButton ID="ImageButton6" runat="server" Height="48px" ImageUrl="~/IconsPack/Approved.png" ToolTip="Approve Record" CssClass="morph" Width="48px"/>
                <asp:ImageButton ID="ImageButton7" runat="server" Height="48px" ImageUrl="~/IconsPack/Denied.png" ToolTip="Unapprove Record" CssClass="morph" Width="48px"/>
                <asp:ImageButton ID="ImageButton8" runat="server" Height="48px" ImageUrl="~/IconsPack/Update.png" ToolTip="Refresh Table" CssClass="morph" Width="48px"/>
                <hr />
            </div>
        </asp:Panel>
        </asp:ContentPlaceHolder> 

        <asp:ContentPlaceHolder ID="GridViewPlaceHolder" runat="server">
                  <div class="EU_TableScroll" id="showData" style="display: block">
                    <asp:GridView ID="GridView1" runat="server"  CssClass="EU_DataTable" AllowPaging="True"
                        PageSize="7" AutoGenerateColumns="False" EmptyDataText="No Data Available.">
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="CheckBox1" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                      </asp:GridView>
                </div>
        </asp:ContentPlaceHolder>
        <asp:ContentPlaceHolder ID="DataSource" runat="server">

        </asp:ContentPlaceHolder>
        <div class="clear">          
        </div>
    </div>
    <div class="footer">
    </div>
    </form>
</body>
</html>

使用上面的母版页的子页面示例。

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/JSPayroll/JSPSite.Master" CodeBehind="PaymentRules.aspx.vb" Inherits="SSPayroll.PaymentRules" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>


<asp:Content ID="DS" ContentPlaceHolderID ="DataSource" runat ="server">

    <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=sspEntities" DefaultContainerName="sspEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="GeneralRules">
    </asp:EntityDataSource>

</asp:Content>

基本上我想做的是..在我的子页面中,只需为每个页面配置数据源,从主页面和预制件我的任务将其附加到gridview ..添加,编辑,删除(我的按钮)主页)。我是新手,并不知道如何解决这个问题。一些帮助将不胜感激。此外,如果有人可以告诉我我在做什么实际上是有道理的,而不是添加gridviews和工具栏到我创建的每个页面。请告诉我。谢谢。


已编辑 - 有答案。


Dim ContentPlaceHolder As ContentPlaceHolder
Dim gv As GridView
ContentPlaceHolder = CType(Master.FindControl("GridViewPlaceHolder"), ContentPlaceHolder)
If Not ContentPlaceHolder Is Nothing Then
    gv = CType(ContentPlaceHolder.FindControl("GridView1"), GridView)
      If Not gv Is Nothing Then
        Dim es As EntityDataSource = EntityDataSource1
        gv.DataSource = es
        gv.DataBind()
    End If
End If

1 个答案:

答案 0 :(得分:0)

Dim ContentPlaceHolder As ContentPlaceHolder
Dim gv As GridView
ContentPlaceHolder = CType(Master.FindControl("GridViewPlaceHolder"), ContentPlaceHolder)
If Not ContentPlaceHolder Is Nothing Then
    gv = CType(ContentPlaceHolder.FindControl("GridView1"), GridView)
      If Not gv Is Nothing Then
        Dim es As EntityDataSource = EntityDataSource1
        gv.DataSource = es
        gv.DataBind()
    End If
End If