WebControl.Width 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置 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
属性值
- 属性
例外
Web 服务器控件的宽度设置为负值。
示例
下面的示例演示如何以声明方式设置Width从基类继承的TableWebControl控件的属性。
<%@ 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 的浏览器中的所有控件呈现。 在早期浏览器中不呈现此属性的控件包括 Label、 HyperLink和 LinkButton任何验证控件。 如果CheckBoxList此属性RepeatLayout设置为 RepeatLayout.Flow,并且DataList也不会RadioButtonList在早期浏览器中呈现此属性。 此外,早期浏览器仅支持单元类型 Pixel ,并且 Percentage 受支持。
由于此属性是非标准 HTML,因此,显示为表的 Web 服务器控件(例如 Table ,并且 DataGrid)在早于 Microsoft Internet Explorer 版本 4 的浏览器中不支持此属性。
注释
若要以声明方式将 Width 属性设置为非默认值的 Pixel单元类型,必须创建特定于所需单位类型的新单元类型。 例如,若要将 Width 控件的属性设置为百分比值 100,可以执行以下操作:
myWebControl.width = Unit.Percentage(100);