locked
DropDownCheckBoxes checked items in a label RRS feed

  • Question

  • User2001432087 posted

    Hi ,

      I am having a DropDownCheckBoxes  in my application. When I checked items in DropDownCheckBoxes the values will automatically bind to a label and removed when I unchecked the items from the DropDownCheckBoxes . Need to display dynamically using javascript.

    Thanks 

    Monday, October 24, 2016 7:54 AM

All replies

  • User-707554951 posted

    Hi ykkumar13,

    Based on your needs, I suggest you could use Jquery. I make an example, I suggest you could refer to it:

    <%@ Register TagPrefix="asp" Namespace="Saplin.Controls" Assembly="DropDownCheckBoxes" %>

           <asp:DropDownCheckBoxes runat="server" ID="DropDownCheckBoxes1" Width="180px" UseSelectAllNode = "false">
                <Style SelectBoxWidth="195" DropDownBoxBoxWidth="160" DropDownBoxBoxHeight="90" />
        <Items>
            <asp:ListItem Text="Mango" Value="1"></asp:ListItem>
            <asp:ListItem Text="Apple" Value="2"></asp:ListItem>
            <asp:ListItem Text="Banana" Value="3"></asp:ListItem>
        </Items>
                </asp:DropDownCheckBoxes>
                <asp:ExtendedRequiredFieldValidator ID = "ExtendedRequiredFieldValidator1" runat = "server" ControlToValidate = "DropDownCheckBoxes1" ErrorMessage = "Required" ForeColor = "Red"></asp:ExtendedRequiredFieldValidator>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    

    JS:

     <script>
            $(function () {
                $("span#DropDownCheckBoxes1 :checkbox").change(function () {
                    var val = "";
                    $("span#DropDownCheckBoxes1 :checkbox:checked").each(function () {
                        val += $(this).next("label").text();
                    })
                    $("#Label1").text(val);
                })
            })
        </script>

    The output screenshot as below:

    Best regards

    Cathy

    Tuesday, October 25, 2016 12:32 PM