WebControl.BorderColor Property
Assembly: System.Web (in system.web.dll)
/** @property */ public Color get_BorderColor () /** @property */ public void set_BorderColor (Color value)
public function get BorderColor () : Color public function set BorderColor (value : Color)
Property Value
A Color that represents the border color of the control. The default is Empty, which indicates that this property is not set.Use the BorderColor property to specify the border color of the Web Server control. This property is set using a Color object.
Note |
|---|
| The BorderColor property will render only for certain controls. For example, the Table, Panel, DataGrid, Calendar, and ValidationSummary controls will render this property. It will also work for the CheckBoxList, RadioButtonList, and DataList controls, if their RepeatLayout property is set to RepeatLayout.Table, not RepeatLayout.Flow. However, it is rendered as the bordercolor attribute, which is not part of the HTML 3.2 standard. The bordercolor attribute works for Microsoft Internet Explorer version 3.0 or later, but not most other browsers. |
When the BorderColor property is not set, the browser will use its default border color. Refer to your browser to determine its default color scheme.
The following example illustrates how to set the BorderColor property of the Table control, which is inherited from the WebControl base class.
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <body> <h3>BorderColor Property of a Web Control</h3> <form runat=server> <asp:Table id="Table1" runat="server" CellPadding=10 GridLines="Both" BorderColor="Brown" > <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> </form> </body> </html>
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 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" %> <HTML> <HEAD> <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(); colors.Add(Color.Black.Name); colors.Add(Color.Blue.Name); colors.Add(Color.Green.Name); colors.Add(Color.Orange.Name); colors.Add(Color.Purple.Name); colors.Add(Color.Red.Name); colors.Add(Color.White.Name); colors.Add(Color.Yellow.Name); // Bind the colors collection to the borderColorList. borderColorList.DataSource = colors; borderColorList.DataBind(); // Create a ListItemCollection and the add names of // the BorderStyle enumeration values. ListItemCollection styles = new ListItemCollection(); foreach (string s in Enum.GetNames(typeof(BorderStyle))) { styles.Add(s); } // Bind the styles collection to the borderStyleList. borderStyleList.DataSource = styles; borderStyleList.DataBind(); // 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; borderWidthList.DataBind(); } } // 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), borderStyleList.SelectedItem.Text); } // 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); } </SCRIPT> </HEAD> <BODY> <form runat="server"> <h3> Border Properties Example </h3> <table border="0" cellpadding="6"> <tr> <td> <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 </center></asp:Label> </td> <td> <asp:DropDownList Runat="server" ID="borderColorList" OnSelectedIndexChanged="ChangeBorderColor" AutoPostBack="True" EnableViewState="True"></asp:DropDownList> <br> <br> <asp:DropDownList Runat="server" ID="borderStyleList" OnSelectedIndexChanged="ChangeBorderStyle" AutoPostBack="True" EnableViewState="True"></asp:DropDownList> <br> <br> <asp:DropDownList Runat="server" ID="borderWidthList" OnSelectedIndexChanged="ChangeBorderWidth" AutoPostBack="True" EnableViewState="True"></asp:DropDownList> </td> </tr> </table> </form> </body> </HTML>
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.
Reference
WebControl ClassWebControl Members
System.Web.UI.WebControls Namespace
System.Drawing.Color
Style Class
Table Class
Panel Class
DataGrid Class
Calendar Class
ValidationSummary Class
CheckBoxList Class
RadioButtonList Class
DataList Class
RepeatLayout Enumeration
Other Resources
ASP.NET Web Server Controls and Browser CapabilitiesWeb Server Control Syntax
Developing Custom ASP.NET Server Controls
Note