How to enable/disable dropdownlist through a checkbox selection

In this post,I will show you how to enable/disable dropdownlist control through checkbox selection in

  • Create a new website 
  • Right click on the website,add a new webpage,and add following code into it

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#chkEnable").click(function () {
                if (this.checked)
                    $('#ddlList').attr('disabled', 'disabled');
    <form id="form1" runat="server">
        <asp:CheckBox ID="chkEnable" runat="server" Text="Enable/Disable" /><br />
        <asp:DropDownList ID="ddlList" runat="server">
            <asp:ListItem Text="Select" Value="-1">
            <asp:ListItem Text="Option1" Value="1" />
            <asp:ListItem Text="Option2" Value="2" />
            <asp:ListItem Text="Option3" Value="3" />

{Click here for live demo}

No comments:

Post a Comment