WebControl.Height 属性

定义

获取或设置 Web 服务器控件的高度。Gets or sets the height of the Web server control.

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; }
member this.Height : System.Web.UI.WebControls.Unit with get, set
Public Overridable Property Height As Unit

属性值

表示控件高度的 UnitA Unit that represents the height of the control. 默认值为 EmptyThe default is Empty.

属性

异常

高度被设置为负值。The height was set to a negative value.

示例

下面的示例演示如何以声明方式设置HeightWebControl基类继承Table的控件的属性。The following example illustrates how to declaratively set the Height property of the Table control, inherited from the WebControl base class.

<%@ 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 服务器控件的高度。Use the Height property to specify the height of the Web server control.

备注

对于早于 Microsoft Internet Explorer 版本4的浏览器中的所有控件,此属性不会呈现。This property does not render for all controls in browsers earlier than Microsoft Internet Explorer version 4. 不在早期浏览器中呈现此属性的控件Label包括HyperLink LinkButton、、和任何验证控件。Controls that do not render this property in earlier browsers include Label, HyperLink, LinkButton, and any validation controls. RadioButtonList DataList当属性设置为CheckBoxList RepeatLayout时,和不在早期浏览器中呈现此属性。 RepeatLayout.FlowThe CheckBoxList, RadioButtonList and DataList also do not render this property in earlier browsers when their RepeatLayout property is set to RepeatLayout.Flow. 而且,在早期的浏览PixelPercentage中仅支持和的单位类型。Furthermore, only unit types of Pixel and Percentage are supported in earlier browsers.

由于此属性是非标准 HTML,显示为表的 Web 服务器控件(例如TableDataGrid)在早于 Microsoft Internet Explorer 版本4的浏览器中不支持此属性。Because this property is nonstandard HTML, Web server controls that display as a table, such as Table and DataGrid, do not support this property in browsers earlier than Microsoft Internet Explorer version 4.

备注

若要将Height属性设置为Pixel默认值以外的单位类型,必须创建特定于所需单位类型的新单位类型。To set the Height property to a unit type other than the default of Pixel, you must create a new unit type specific to the unit type you want. 例如,若要将控件的Height属性设置为百分比值100,则可以执行以下操作:For example, to set a control's Height property to a percentage value of 100, you could do the following:

myWebControl.Width = Unit.Percentage(100);

有关可用于Height属性的单位类型的详细信息, Unit请参阅类。For more information on the unit types available for the Height property, see the Unit class.

适用于

另请参阅