This documentation is archived and is not being maintained.

WebControl.BorderWidth Property

Gets or sets the border width of the Web server control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual Unit BorderWidth { get; set; }
/** @property */
public Unit get_BorderWidth ()

/** @property */
public void set_BorderWidth (Unit value)

public function get BorderWidth () : Unit

public function set BorderWidth (value : Unit)

Property Value

A Unit that represents the border width of a Web server control. The default value is Empty, which indicates that this property is not set.

Exception typeCondition


The specified border width is a negative value.

Use the BorderWidth property to specify a border width for a control.


This property does not work with all Web server controls. It applies only to controls that display as a table, such as Table and DataGrid.

This property is set with a Unit object. If the Value property of the Unit contains a negative number, an exception is thrown.


The border width can be expressed only in pixels for browsers earlier than Microsoft Internet Explorer version 5. All unit types are supported in Microsoft Internet Explorer version 5 and later. Refer to the specific control for details.

The following example illustrates how to set the BorderWidth property of the Table control, inherited from the WebControl base class.

<%@ Page Language="C#" AutoEventWireup="True" %>
     <h3>BorderWidth Property of a Web Control</h3>
 <form runat=server>
 <asp:Table id="Table1" runat="server"
          Row 0, Col 0
          Row 0, Col 1
          Row 1, Col 0
          Row 1, Col 1


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

<!-- This example demonstrates how to set property values for the
BorderColor, BorderStyle, and BorderWidth properties, and how to 
change the property values at run time. -->

...<%@ Page language="c#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>

        <SCRIPT runat="server">
            private void Page_Load(object sender, System.EventArgs e)
                // Determine whether this is the first time the page is loaded;
                // if so, load the drop-down lists with data.
                if (!Page.IsPostBack)
                    // Create a ListItemCollection and add names of colors.
                    ListItemCollection colors = new ListItemCollection();
                    // Bind the colors collection to the borderColorList.
                    borderColorList.DataSource = colors;

                    // Create a ListItemCollection and the add names of 
                    // the BorderStyle enumeration values.
                    ListItemCollection styles = new ListItemCollection();

                    foreach (string s in Enum.GetNames(typeof(BorderStyle)))

                    // Bind the styles collection to the borderStyleList.
                    borderStyleList.DataSource = styles;

                    // Create a ListItemCollection and add width values
                    // expressed in pixels (px).
                    ListItemCollection widths = new ListItemCollection();

                    for (int i = 0; i < 11; i++)
                        widths.Add(i.ToString() + "px");

                    // Bind the widths collection to the borderWidthList.
                    borderWidthList.DataSource = widths;


            // This method handles the SelectedIndexChanged event for borderColorList.
            public void ChangeBorderColor(object sender, System.EventArgs e)
                // Convert the color name string to an object of type Color, 
                // and set the Color as the new border color for Label1.
                Label1.BorderColor = Color.FromName(borderColorList.SelectedItem.Text);

            // This method handles the selectedIndexChanged event for boderStyleList.
            public void ChangeBorderStyle(object sender, System.EventArgs e)
                // Convert the style name string to a BorderStyle enumeration value,
                // and set the BorderStyle as the new border style for Label1.
                Label1.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle),

            // This method handles the SelectedIndexChanged event for borderWidthList.
            public void ChangeBorderWidth(object sender, System.EventArgs e)
                // Convert the border width string to a object of type Unit,
                // and set the Unit as the new border width for Label1.
                Label1.BorderWidth = Unit.Parse(borderWidthList.SelectedItem.Text);

        <form runat="server">

            <h3> Border Properties Example </h3>

            <table border="0" cellpadding="6">
                        <asp:Label Runat="server" BorderColor="Black" 
                            BorderStyle="Solid" BorderWidth="4px" ID="Label1" 
                            Text="Border Properties Example" Height="75" 
                            Width="200"><center><br>Border Properties Example

                        <asp:DropDownList Runat="server" ID="borderColorList" 
                            OnSelectedIndexChanged="ChangeBorderColor" AutoPostBack="True" 
                        <asp:DropDownList Runat="server" ID="borderStyleList" 
                            OnSelectedIndexChanged="ChangeBorderStyle" AutoPostBack="True" 
                        <asp:DropDownList Runat="server" ID="borderWidthList" 
                            OnSelectedIndexChanged="ChangeBorderWidth" AutoPostBack="True"

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0