我的aspx页面中有一个 gridview ,其中母版页。
运行aspx页面时,它不会在内容页面中显示 gridview ,而是在aspx页面顶部。
当我删除gridview并放置一些简单的文本代替它时,它不起作用。
请帮帮我。
我的下面的代码。
母版页
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Mpdue.master.cs" Inherits="Mpdue" %>
<!DOCTYPE html>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ScriptManager ID="ScriptManager" EnableScriptGlobalization="true" EnableScriptLocalization="true"
runat="server">
</asp:ScriptManager>
<div>
<div id="generale">
<div id="header">
<div id="headerLeft">
</div>
<div id="headerRight">
</div>
<div class="clear">
</div>
</div>
<div id="login">
<div id="loginLeft">
</div>
<div id="loginCenter">
<asp:Label ID="lbWelcome" runat="server">
</asp:Label>
</div>
<div id="loginRight">
</div>
<div class="clear">
</div>
</div>
<br />
<fieldset>
<legend style="font-size: 12px; font-weight: bold; color: Red; margin-left: 10px;">
</legend>
</fieldset>
<div id="footer">
<div id="footerLeft">
</div>
<div id="footerCenter">
</div>
<div id="footerRight">
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
aspx页面
<%@ Page Title="" Language="C#" MasterPageFile="Mpdue.master" AutoEventWireup="true" CodeFile="sDefault.aspx.cs" Inherits="sDefault" %>
<%@ MasterType VirtualPath="Mpdue.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:Panel ID="pngvProducts" runat="server">
<asp:GridView ID="gvProducts" AutoGenerateColumns="False" EmptyDataText="No data" EnableViewState="true"
runat="server" DataKeyNames="sID" CssClass="mGrid" Width="500" HorizontalAlign="Center"
AllowPaging="True" PageSize="15"
OnPageIndexChanging="gvProducts_PageIndexChanging"
OnRowDataBound="gvProducts_RowDataBound">
<AlternatingRowStyle CssClass="altrows" />
<Columns>
<%--Column 0--%>
<asp:TemplateField HeaderText="N." ItemStyle-CssClass="ddl_Class_new" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Container.DataItemIndex + 1%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/aspnet/Img/bot_back_doppio.gif"
CommandArgument="First" CommandName="Page" />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="/aspnet/Img/bot_back.gif"
CommandArgument="Prev" CommandName="Page" />
Pagina
<asp:DropDownList ID="ddlPages" runat="server" AutoPostBack="True" CssClass="ddl_Class"
OnSelectedIndexChanged="ddlPages_SelectedIndexChanged">
</asp:DropDownList>
di
<asp:Label ID="lblPageCount" runat="server"></asp:Label>
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="/aspnet/Img/bot_next.gif"
CommandArgument="Next" CommandName="Page" />
<asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="/aspnet/Img/bot_next_doppio.gif"
CommandArgument="Last" CommandName="Page" />
</PagerTemplate>
</asp:GridView>
</asp:Panel>
</asp:Content>
答案 0 :(得分:2)
您已将ContentPlaceHolder放置在其他任何地方的上方,因此内容当然会在标题的上方。 您需要将ContentPlaceHolder放置在要放置内容的“母版”位置。
<form id="form1" runat="server">
<div>
<div>
<div id="generale">
<div id="header">
</div>
<div id="login">
</div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
<fieldset>
<legend style="font-size: 12px; font-weight: bold; color: Red; margin-left: 10px;"></legend>
</fieldset>
<div id="footer">
</div>
</div>
</div>
</div>
</form>