WebPartZoneBase.LayoutOrientation 属性

定义

获取或设置指示区域中的控件是垂直排列还是水平排列的值。

public:
 virtual property System::Web::UI::WebControls::Orientation LayoutOrientation { System::Web::UI::WebControls::Orientation get(); void set(System::Web::UI::WebControls::Orientation value); };
public virtual System.Web.UI.WebControls.Orientation LayoutOrientation { get; set; }
member this.LayoutOrientation : System.Web.UI.WebControls.Orientation with get, set
Public Overridable Property LayoutOrientation As Orientation

属性值

Orientation

确定区域中控件的排列方式的 Orientation 值。 默认方向为 Vertical

例外

该值不是枚举的 Orientation 值之一。

示例

下面的代码示例演示了控件上WebPartZone属性的LayoutOrientation声明性和编程用法。 有关完整代码示例(包括代码隐藏源文件和包含此代码中的区域的 .aspx 页)请参阅 WebPartZoneBase 类概述。

请注意,该 LayoutOrientation 属性在声明性标记中为其分配了一个值。 将页面加载到浏览器中后,此值会影响 WebPartZone1此值。 区域中的Web 部件控件水平呈现。

<asp:WebPartZone 
  ID="WebPartZone1" 
  Runat="server"
  LayoutOrientation="Vertical" >
  <EditVerb Text="Edit WebPart" />
  <SelectedPartChromeStyle BackColor="LightBlue" />
  <ZoneTemplate>
    <asp:BulletedList 
      ID="BulletedList1" 
      Runat="server"
      DisplayMode="HyperLink" 
      Title="Favorite Links" >
      <asp:ListItem Value="http://msdn.microsoft.com">
        MSDN
      </asp:ListItem>
      <asp:ListItem Value="http://www.asp.net">
        ASP.NET
      </asp:ListItem>
      <asp:ListItem Value="http://www.msn.com">
        MSN
      </asp:ListItem>
    </asp:BulletedList>
    <asp:Calendar ID="Calendar1" Runat="server" 
      Title="My Calendar" />
  </ZoneTemplate>
</asp:WebPartZone>
<asp:WebPartZone 
  ID="WebPartZone1" 
  Runat="server"
  LayoutOrientation="Vertical" >
  <EditVerb Text="Edit WebPart" />
  <SelectedPartChromeStyle BackColor="LightBlue" />
  <ZoneTemplate>
    <asp:BulletedList 
      ID="BulletedList1" 
      Runat="server"
      DisplayMode="HyperLink" 
      Title="Favorite Links" >
      <asp:ListItem Value="http://msdn.microsoft.com">
        MSDN
      </asp:ListItem>
      <asp:ListItem Value="http://www.asp.net">
        ASP.NET
      </asp:ListItem>
      <asp:ListItem Value="http://www.msn.com">
        MSN
      </asp:ListItem>
    </asp:BulletedList>
    <asp:Calendar ID="Calendar1" Runat="server" 
      Title="My Calendar" />
  </ZoneTemplate>
</asp:WebPartZone>

可以单击 “切换布局方向 ”按钮来更改区域的方向。 用于切换方向的代码在以下代码示例中从分部类发生。

protected void Button2_Click(object sender, EventArgs e)
{
  if (WebPartZone1.LayoutOrientation == Orientation.Vertical)
    WebPartZone1.LayoutOrientation = Orientation.Horizontal;
  else
    WebPartZone1.LayoutOrientation = Orientation.Vertical;
  Page_Load(sender, e);
}
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) 
  If WebPartZone1.LayoutOrientation = Orientation.Vertical Then
      WebPartZone1.LayoutOrientation = Orientation.Horizontal
  Else
      WebPartZone1.LayoutOrientation = Orientation.Vertical
  End If
  Page_Load(sender, e)
End Sub

注解

LayoutOrientation属性涉及如何在区域中布局Web 部件控件。 使用默认 Vertical 方向时,控件会根据 ZoneIndex 每个控件的值以从上到下排列呈现。 Horizontal使用方向时,控件按区域宽度并排排列。

Internet Explorer 可能会影响控件的高度 WebPart 以及包含控件的区域的高度。 Internet Explorer 以兼容模式呈现网页, (与以前的浏览器版本) 向后兼容,或在标准模式下 (由页面) 中存在 DOCTYPE 声明决定。 有关这些模式的信息,请参阅 DHTML compatMode 属性。 当 Internet Explorer 以标准模式呈现页面时,在某些情况下,即使单元格的 HTML 标记是 <td height="100%">,它也不会重设表格中的单元格大小。 因此, WebPart 控件及其包含区域呈现,以便控件不会拉伸到区域的完整高度。

这种呈现发生在两种情况下。

  • 当区域 LayoutOrientation 的属性设置为 Vertical时,你显式设置该区域的高度。 若要使控件能够填充区域的完整高度,请不要指定水平区域的高度。

  • 当区域 LayoutOrientation 的属性设置为 Horizontal时,不会显式设置区域的高度 (或包含控件) 。 若要使控件能够填充区域的完整高度,请设置区域的高度或垂直区域中的控件的高度。

本主题中的代码示例演示属性 LayoutOrientation 的正常用法。 有关演示高度相关的呈现问题的代码示例以及如何解决此问题,请参阅 Height 该属性。

适用于

另请参阅