使用英语阅读

通过


WebControl.Height 属性

定义

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

C#
[System.ComponentModel.Bindable(true)]
public virtual System.Web.UI.WebControls.Unit Height { get; set; }
C#
public virtual System.Web.UI.WebControls.Unit Height { get; set; }

属性值

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

属性

例外

高度被设置为负值。

示例

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

ASP.NET (C#)
<%@ 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>

注解

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

备注

此属性不会为 Microsoft Internet Explorer 版本 4 之前的浏览器中的所有控件呈现。 在早期浏览器中不呈现此属性的控件包括 LabelHyperLinkLinkButton和任何验证控件。 当 CheckBoxListRadioButtonListDataList 和 的 属性设置为 RepeatLayout.Flow时,也不会RepeatLayout在早期浏览器中呈现此属性。 此外,早期浏览器仅支持 和 PercentagePixel单元类型。

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

备注

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

myWebControl.Width = Unit.Percentage(100);

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

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另请参阅