Enable and Disable DropDownList programmatically
dropdownlist is an asp.net list web server control. this control allow the users to select a single item at a time.
.net developers dynamically enable or disable a dropdownlist control within a web page depending on various criteria.
the following c# example source code demonstrate us how can we enabled a disabled dropdownlist or disabled a enabled
dropdownlist programmatically at run time in asp.net. code explain how developers can switch between dropdownlist
enabled and disabled state dynamically.
dropdownlist Enabled property get or set a value that indicate whether dropdownlist server control is enabled. this property accept a boolean value. by setting its value True we can enable a disabled dropdownlist. and by using its value False we can disable a dropdownlist in web page. disable states dropdownlist typically appears dimmed in browser user interface.
dropdownlist Enabled property get or set a value that indicate whether dropdownlist server control is enabled. this property accept a boolean value. by setting its value True we can enable a disabled dropdownlist. and by using its value False we can disable a dropdownlist in web page. disable states dropdownlist typically appears dimmed in browser user interface.
DropDownListDisable.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
DropDownList1.Enabled = false;
}
protected void Button2_Click(object sender, System.EventArgs e)
{
DropDownList1.Enabled = true;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to enable, disable DropDownList programmatically</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">DropDownList: Enable, Disable</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Bold="true"
ForeColor="IndianRed"
Text="asp.net controls"
>
</asp:Label>
<asp:DropDownList
ID="DropDownList1"
runat="server"
>
<asp:ListItem>ConnectionsZone</asp:ListItem>
<asp:ListItem>LoginView</asp:ListItem>
<asp:ListItem>SiteMapPath</asp:ListItem>
<asp:ListItem>ListBox</asp:ListItem>
<asp:ListItem>LayoutEditorPart</asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Font-Bold="true"
ForeColor="IndianRed"
Text="Disable DropDownList"
OnClick="Button1_Click"
/>
<asp:Button
ID="Button2"
runat="server"
Font-Bold="true"
ForeColor="IndianRed"
Text="Enable DropDownList"
OnClick="Button2_Click"
/>
</div>
</form>
</body>
</html>

