Duration (Pacific Standard Time):
To (Pacific Standard Time):
User Action:

WebControl.BorderStyle Property


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

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

Public Overridable Property BorderStyle As BorderStyle

Property Value

Type: System.Web.UI.WebControls.BorderStyle

One of the BorderStyle enumeration values. The default is NotSet.

Use the BorderStyle property to specify the border style for the Web server control. This property is set using one of the BorderStyle enumeration values. The following table lists the possible values.

Border Style



The border style is not set.


No border


A dotted line border.


A dashed line border.


A solid line border.


A solid double line border.


A grooved border for a sunken border appearance.


A ridged border for a raised border appearance.


An inset border for a sunken control appearance.


An outset border for a raised control appearance.

System_CAPS_note Note

This property will not render on browsers earlier than Microsoft Internet Explorer 4 for any Web server control. There is no equivalent to it in HTML 3.2.

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

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<script runat="server">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>BorderStyle Property</title>
    <form id="form1" runat="server">
        <h3>BorderStyle Property of a Web Control</h3>

        <asp:Table id="Table1" runat="server"
            CellPadding = "10" 

                    Row 0, Col 0
                    Row 0, Col 1

                    Row 1, Col 0
                    Row 1, Col 1
System_CAPS_note Note

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 Forms 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="VB" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">
    Private Sub Page_Load(sender As Object, e As System.EventArgs)
        ' Determine whether this is the first time the page is loaded;
        ' if so, load the drop-down lists with data.
        If Not Page.IsPostBack Then
            ' Create a ListItemCollection and add names of colors.
            Dim colors As New ListItemCollection()
            ' Bind the colors collection to the borderColorList.
            borderColorList.DataSource = colors

            ' Create a ListItemCollection and the add names of 
            ' the BorderStyle enumeration values.
            Dim styles As New ListItemCollection()
            Dim styleType As Type = GetType(BorderStyle)

            Dim s As String
            For Each s In  [Enum].GetNames(styleType)
            Next s

            ' Bind the styles collection to the borderStyleList.
            borderStyleList.DataSource = styles

            ' Create a ListItemCollection and add width values
            ' expressed in pixels (px).
            Dim widths As New ListItemCollection()

            Dim i As Integer
            For i = 0 To 10
                widths.Add(i.ToString() & "px")
            Next i

            ' Bind the widths collection to the borderWidthList.
            borderWidthList.DataSource = widths
        End If
    End Sub

    ' This method handles the SelectedIndexChanged event for borderColorList.
    Public Sub ChangeBorderColor(sender As Object, e As System.EventArgs)
        ' 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)
    End Sub

    ' This method handles the selectedIndexChanged event for boderStyleList.
    Public Sub ChangeBorderStyle(sender As Object, e As System.EventArgs)
        ' Convert the style name string to a BorderStyle enumeration value,
        ' and set the BorderStyle as the new border style for Label1.
        Dim styleType As Type = GetType(BorderStyle)
        Label1.BorderStyle = [Enum].Parse(styleType, borderStyleList.SelectedItem.Text)
    End Sub

    ' This method handles the SelectedIndexChanged event for borderWidthList.
    Public Sub ChangeBorderWidth(sender As Object, e As System.EventArgs)
        ' 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)
    End Sub
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title> Border Properties Example </title>

        <form id="form1" 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" 
                        <br />
                        <br />
                        <asp:DropDownList Runat="server" ID="borderStyleList" 
                            OnSelectedIndexChanged="ChangeBorderStyle" AutoPostBack="True" 
                        <br />            
                        <br />
                        <asp:DropDownList Runat="server" ID="borderWidthList" 
                            OnSelectedIndexChanged="ChangeBorderWidth" AutoPostBack="True"
.NET Framework
Available since 1.1
Return to top