WebControl.Width 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定網頁伺服器控制的寬度。
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
屬性值
- 屬性
例外狀況
網頁伺服器控制的寬度被設定為負值。
範例
以下範例說明如何宣告式設定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 來指定網頁伺服器控制項的寬度。
備註
此屬性不適用於 Microsoft Internet Explorer 4 之前的所有瀏覽器控制項。 早期瀏覽器中不呈現此屬性的控制項包括 Label、 HyperLink、 LinkButton及任何驗證控制項。
CheckBoxList當 的 RadioButtonListDataList屬性設為 RepeatLayout.Flow時,在早期瀏覽器RepeatLayout中 , 以及 並不會呈現此屬性。 此外,早期瀏覽器僅支援 和 Percentage 的單位類型Pixel。
由於此屬性為非標準 HTML,顯示為表格的網頁伺服器控制項(如 Table 和 DataGrid)在 Microsoft Internet Explorer 4 版本之前的瀏覽器中不支援此屬性。
備註
若要將屬性宣告性地設定 Width 為非預設的 Pixel單位類型,您必須建立一個特定於你想要的單位類型的新單位類型。 例如,要將控制項 Width 屬性設定為 100 的百分比值,你可以這樣做:
myWebControl.width = Unit.Percentage(100);