1

编辑:

当前布局:

在此处输入图像描述

我试图弄清楚如何在我的 ASP 网页设计中将一个 div(服务器端)定位在另一个 div 下。

对于我的问题,我将使用以下屏幕截图:

目前这是我的布局:

在此处输入图像描述

我想在另一个下放置 2 个 div 给我一个 'title' div 和一个 'description' div tat 稍后将由我的数据库结果填充,如图所示:

在此处输入图像描述

这是我当前的源代码。有人可以将我推向正确的方向,即我如何像这样将这些 div 置于另一个之上吗?

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"  CodeBehind="Show.aspx.cs" Inherits="ViewCDs.Show" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

     <div style=" float:left;">
     <asp:Image ID="Image1" runat="server" Height="145px" ViewStateMode="Enabled" 
     Width="185px" />

      </div>
      <div style=" float:left; width: 395px; height: 140px;">

      <asp:FormView ID="FormView1" runat="server">
       <EditItemTemplate>
           coffeeName:
           <asp:TextBox ID="coffeeNameTextBox" runat="server" 
               Text='<%# Bind("coffeeName") %>' />
           <br />
           coffeeOrigin:
           <asp:TextBox ID="coffeeOriginTextBox" runat="server" 
               Text='<%# Bind("coffeeOrigin") %>' />
           <br />
           coffeeStrength:
           <asp:TextBox ID="coffeeStrengthTextBox" runat="server" 
               Text='<%# Bind("coffeeStrength") %>' />
           <br />
           coffeeGrind:
           <asp:TextBox ID="coffeeGrindTextBox" runat="server" 
               Text='<%# Bind("coffeeGrind") %>' />
           <br />
           coffeePrice:
           <asp:TextBox ID="coffeePriceTextBox" runat="server" 
               Text='<%# Bind("coffeePrice") %>' />
           <br />
           coffeeQty:
           <asp:TextBox ID="coffeeQtyTextBox" runat="server" 
               Text='<%# Bind("coffeeQty") %>' />
           <br />
           coffeeRRP:
           <asp:TextBox ID="coffeeRRPTextBox" runat="server" 
               Text='<%# Bind("coffeeRRP") %>' />
           <br />
           <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
               CommandName="Update" Text="Update" />
           &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
               CausesValidation="False" CommandName="Cancel" Text="Cancel" />
          </EditItemTemplate>
          <InsertItemTemplate>
           coffeeName:
           <asp:TextBox ID="coffeeNameTextBox" runat="server" 
               Text='<%# Bind("coffeeName") %>' />
           <br />
           coffeeOrigin:
           <asp:TextBox ID="coffeeOriginTextBox" runat="server" 
               Text='<%# Bind("coffeeOrigin") %>' />
           <br />
           coffeeStrength:
           <asp:TextBox ID="coffeeStrengthTextBox" runat="server" 
               Text='<%# Bind("coffeeStrength") %>' />
           <br />
           coffeeGrind:
           <asp:TextBox ID="coffeeGrindTextBox" runat="server" 
               Text='<%# Bind("coffeeGrind") %>' />
           <br />
           coffeePrice:
           <asp:TextBox ID="coffeePriceTextBox" runat="server" 
               Text='<%# Bind("coffeePrice") %>' />
           <br />
           coffeeQty:
           <asp:TextBox ID="coffeeQtyTextBox" runat="server" 
               Text='<%# Bind("coffeeQty") %>' />
           <br />
           coffeeRRP:
           <asp:TextBox ID="coffeeRRPTextBox" runat="server" 
               Text='<%# Bind("coffeeRRP") %>' />
           <br />
           <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
               CommandName="Insert" Text="Insert" />
           &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
               CausesValidation="False" CommandName="Cancel" Text="Cancel" />
           </InsertItemTemplate>
           <ItemTemplate>

           <b>Origin:</b>
           <asp:Label ID="coffeeOriginLabel" runat="server" 
               Text='<%# Bind("coffeeOrigin") %>' />
           <br />
           <br />
           <b>Grind:</b>
           <asp:Label ID="coffeeGrindLabel" runat="server" 
               Text='<%# Bind("coffeeGrind") %>' />
           <br />
           <br />
           <b>Price: £</b>
           <asp:Label ID="coffeePriceLabel" runat="server" 
               Text='<%# Bind("coffeePrice") %>' />
           <br />
           <br />
               <b>Strength:</b>
           <asp:Label ID="coffeeStrengthLabel" runat="server" 
               Text='<%# Bind("coffeeStrength") %>' />
           <br />
           <br />
           <b>Stock Level:</b>
           <asp:Label ID="coffeeQtyLabel" runat="server" Text='<%# Bind("coffeeQty") %>' />
           <br />


 </ItemTemplate>
 </asp:FormView>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
       ConnectionString="<%$ ConnectionStrings:CoffeeConnectionString %>" 
       SelectCommand="SELECT [coffeeName], [coffeeOrigin], [coffeeStrength], [coffeeGrind], [coffeePrice], [coffeeQty], [coffeeRRP] FROM [Coffees]">
</asp:SqlDataSource>

<br />
</div>

<div style=" float:left; width: 339px; height: 140px;">
<br />

<div style=" float:left; width: 165px; height: 25px;">

    <b><asp:Label ID="Label1" runat="server" Text="Select Coffee Grind:"></asp:Label>  </b>
</div>

<div style=" float:right; width: 165px; height: 25px;">
<asp:DropDownList ID="DropDownList1" runat="server" Height="21px" Width="161px">
    <asp:ListItem>Beans</asp:ListItem>
    <asp:ListItem>Smooth</asp:ListItem>
    <asp:ListItem>Course</asp:ListItem>
 </asp:DropDownList>
 </div>

  <div style=" float:left; width: 165px; height: 40px;">
  <br />
      <b><asp:Label ID="Label2" runat="server" Text="Quantity:"></asp:Label></b>
 </div>

  <div style=" float:right; width: 165px; height: 40px;">
  <br />

      <asp:TextBox ID="TextBox1" runat="server" Width="40px">1</asp:TextBox>

  </div>

  <div style=" float:left; width: 165px; height: 40px;">
  <br />

      <asp:Button ID="Button1" runat="server" Text="Buy" />

 </div>
 </div>

4

1 回答 1

1

您只需要在该代码下方再添加两个 div。

<div id="title"> </div> <br/>
<div id="description"> </div> <br/>

但是,如果您想控制它们的属性,例如可见性,那么您只需要制作这些 asp.net 面板。

<asp:Panel runat="server" ID="title"> </asp:Panel> <br/>
<asp:Panel runat="server" ID="description"> </asp:Panel> <br/>
于 2013-03-23T16:04:05.650 回答