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 繼承自 WebControl 基類之 Table 控制項的 屬性。

<%@ 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.FlowRepeatLayoutRadioButtonListDataList 也不會在舊版瀏覽器中轉譯這個屬性。 此外,舊版瀏覽器只支援 和 PercentagePixel 單位類型。

因為這個屬性不是標準 HTML,所以顯示為數據表的網頁伺服器控制項,例如 TableDataGrid ,在 Microsoft Internet Explorer 第 4 版之前的瀏覽器中不支援此屬性。

注意

若要將 Height 屬性設定為預設值 Pixel 以外的單位類型,您必須建立您想要之單位類型特定的新單位類型。 例如,若要將控制項的 Height 屬性設定為百分比值 100,您可以執行下列動作:

myWebControl.Width = Unit.Percentage(100);

如需屬性可用 Height 單位類型的詳細資訊,請參閱 類別 Unit

適用於

另請參閱