2013-08-20 177 views
1

我想創建一個主頁面,它具有一個工具欄(添加,編輯,刪除,批准,取消批准)以及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和工具欄到我創建的每個頁面。請告訴我。謝謝。


EDITED - With Answer。


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 
+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 
相關問題