通过


WebControl.Height 属性

定义

获取或设置 Web 服务器控件的高度。

public:
 virtual property System::Web::UI::WebControls::Unit Height { System::Web::UI::WebControls::Unit get(); void set(System::Web::UI::WebControls::Unit value); };
[System.ComponentModel.Bindable(true)]
public virtual System.Web.UI.WebControls.Unit Height { get; set; }
public virtual System.Web.UI.WebControls.Unit Height { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Height : System.Web.UI.WebControls.Unit with get, set
member this.Height : System.Web.UI.WebControls.Unit with get, set
Public Overridable Property Height As Unit

属性值

一个 Unit 表示控件的高度。 默认值为 Empty

属性

例外

高度设置为负值。

示例

下面的示例演示如何以声明方式设置Height从基类继承的TableWebControl控件的属性。

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Table Property</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Property of a Table Web Control</h3>
 
        <asp:Table id="Table1" runat="server"
            CellPadding = "10" 
            CellSpacing="0"
            GridLines="Both"
            Height="300">

            <asp:TableRow>
                <asp:TableCell>
                    Row 0, Col 0
                </asp:TableCell>
                <asp:TableCell>
                    Row 0, Col 1
                </asp:TableCell>
            </asp:TableRow>

            <asp:TableRow>
                <asp:TableCell>
                    Row 1, Col 0
                </asp:TableCell>
                <asp:TableCell>
                    Row 1, Col 1
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Table Property</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Property of a Table Web Control</h3>
 
        <asp:Table id="Table1" runat="server"
            CellPadding = "10" 
            CellSpacing="0"
            GridLines="Both"
            Height="300">

            <asp:TableRow>
                <asp:TableCell>
                    Row 0, Col 0
                </asp:TableCell>
                <asp:TableCell>
                    Row 0, Col 1
                </asp:TableCell>
            </asp:TableRow>

            <asp:TableRow>
                <asp:TableCell>
                    Row 1, Col 0
                </asp:TableCell>
                <asp:TableCell>
                    Row 1, Col 1
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </div>
    </form>
</body>
</html>

注解

使用 Height 属性指定 Web 服务器控件的高度。

注释

此属性不会为早于 Microsoft Internet Explorer 版本 4 的浏览器中的所有控件呈现。 在早期浏览器中不呈现此属性的控件包括 LabelHyperLinkLinkButton任何验证控件。 如果CheckBoxList此属性RepeatLayout设置为 RepeatLayout.Flow,并且DataList也不会RadioButtonList在早期浏览器中呈现此属性。 此外,早期浏览器仅支持单元类型 Pixel ,并且 Percentage 受支持。

由于此属性是非标准 HTML,因此,显示为表的 Web 服务器控件(例如 Table ,并且 DataGrid)在早于 Microsoft Internet Explorer 版本 4 的浏览器中不支持此属性。

注释

若要将 Height 属性设置为非默认值的 Pixel单元类型,必须创建特定于所需单位类型的新单元类型。 例如,若要将 Height 控件的属性设置为百分比值 100,可以执行以下操作:

myWebControl.Width = Unit.Percentage(100);

有关属性可用的 Height 单元类型的详细信息,请参阅该 Unit 类。

适用于

另请参阅