WebControl.Width 屬性

定義

取得或設定 Web 伺服器控制項的寬度。

public:
 virtual property System::Web::UI::WebControls::Unit Width { 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 Width { get; set; }
public virtual System.Web.UI.WebControls.Unit Width { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Width : System.Web.UI.WebControls.Unit with get, set
member this.Width : System.Web.UI.WebControls.Unit with get, set
Public Overridable Property Width As Unit

屬性值

Unit 代表控制項的寬度。 預設為 Empty

屬性

例外狀況

Web 伺服器控制項的寬度設定為負值。

範例

下列範例說明如何以宣告方式設定 Width 繼承自 WebControl 基類之 Table 控制項的 屬性。

<%@ Page Language="C#" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>WebControl Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Width Property of a Web Control</h3>
    <asp:Table id="Table1" runat="server"
        CellPadding="10" GridLines="Both"
        Width="350">
 
        <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">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>WebControl Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Width Property of a Web Control</h3>
    <asp:Table id="Table1" runat="server"
        CellPadding="10" GridLines="Both"
        Width="350">
 
        <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>

備註

Width使用 屬性來指定 Web 服務器控制項的寬度。

注意

此屬性不會針對 Microsoft Internet Explorer 第 4 版之前的瀏覽器中的所有控制項轉譯。 在舊版瀏覽器中未轉譯此屬性的控制項包括 LabelHyperLinkLinkButton 和任何驗證控制項。 當 和 CheckBoxList 的 屬性設定為 RepeatLayout.FlowRepeatLayoutRadioButtonListDataList 也不會在舊版瀏覽器中轉譯這個屬性。 此外,舊版瀏覽器只支援 和 PercentagePixel 單位類型。

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

注意

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

myWebControl.width = Unit.Percentage(100);

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

適用於

另請參閱