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; }
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

Unit,表示控制項的高度。A Unit that represents the height of the control. 預設為 EmptyThe default is Empty.

屬性

例外狀況

高度被設定為負值。The height was set to a negative value.

範例

下列範例說明如何以宣告方式設定 Height Table 繼承自基類之控制項的屬性 WebControlThe 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. 未在舊版瀏覽器中呈現此屬性的控制項包括 LabelHyperLinkLinkButton 和任何驗證控制項。Controls that do not render this property in earlier browsers include Label, HyperLink, LinkButton, and any validation controls. CheckBoxList RadioButtonList DataList 舊版瀏覽器中,也不會在其 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. 此外, Pixel 舊版瀏覽器僅支援和的單位類型 PercentageFurthermore, only unit types of Pixel and Percentage are supported in earlier browsers.

因為這個屬性是非標準的 HTML,所以以資料表(例如和)形式顯示的 Web 服務器控制項, Table DataGrid 在 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 屬性(property)設定為預設值以外的單位類型 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.

適用於

另請參閱