How to change ListBox border style programmatically in asp.net c#

ListBox Border Style
listbox is an asp.net list web server control that allow developers to render a single or multiple item selection list control in web browser. asp.net developers can set or change listbox control's default border style. listbox BorderStyle property get or set the border style of listbox control. BorderStyle enumeration represents the different border style options for listbox control. BorderStyle enumeration has many members such as Double, Dashed, Dotted, Inset, NotSet, Outset, Ridge, Solid etc. so we can apply listbox control's border to appear as double line, dashed, ridge etc by using its BorderStyle property.

the following c# example code demonstrate us how can we set or change listbox control border style dynamically at run time in asp.net.
ListBoxBorderStyle.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        ListBox1.BorderWidth = 2;
        ListBox1.BorderColor = System.Drawing.Color.SeaGreen;
    }
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        ListBox1.BorderStyle = BorderStyle.Dotted;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        ListBox1.BorderStyle = BorderStyle.Dashed;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to change ListBox border style programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Teal">asp.net ListBox Example: Change BorderStyle</h2>
        <asp:Label 
             ID="Label1" 
             runat="server"
             Text="asp.net Controls"
             Font-Bold="true"
             ForeColor="Tomato"
             >
        </asp:Label>
        <br />
        <asp:ListBox 
             ID="ListBox1"
             runat="server"
             AutoPostBack="false"
             >
             <asp:ListItem>ListBox</asp:ListItem>
             <asp:ListItem>EntityDataSource</asp:ListItem>
             <asp:ListItem>Repeater</asp:ListItem>
             <asp:ListItem>XmlDataSource</asp:ListItem>
             <asp:ListItem>Wizard</asp:ListItem>
        </asp:ListBox>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             Text="ListBox Border Style Dotted"
             Font-Bold="true"
             ForeColor="Tomato"
             OnClick="Button1_Click"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             Text="ListBox Border Style Dashed"
             Font-Bold="true"
             ForeColor="Tomato"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples