Change Border Color dynamically in ASP.NET

September 30, 2013 0 Comments

There is two method for change border color of dropdownlist in . In first method you can use System.Drawing.Color.Blue enumeration for changing color.

DropDownList1.BorderColor = System.Drawing.Color.Red;
In Second method you can use DropDownList1.Attributes.Add() method.

DropDownList1.Attributes.Add("style", "value");

Lets take an simple example . Drop one dropdownlist control to the design page and handle  SelectedIndexChanged event.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        DropDownList1.Attributes.Add("style", "border-color:" + DropDownList1.SelectedItem.Text);
        DropDownList1.BorderWidth = 5;
        DropDownList1.BorderStyle = BorderStyle.Dashed;

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
            Height="22px" onselectedindexchanged="DropDownList1_SelectedIndexChanged"

Change Border Color dynamically in ASP.NET

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google