Click here to Skip to main content
15,896,111 members
Articles / Web Development / ASP.NET

A Multiple Selection DropDownList (a CheckBoxList Inside a DropDownList)

Rate me:
Please Sign up or sign in to vote.
4.52/5 (22 votes)
19 Mar 2010CPOL2 min read 259.4K   18.6K   65  
Check and mark more than one option in a DropDownList
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MultiCheckCombo.ascx.cs" Inherits="SRL.UserControls.MultiCheckCombo" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<script type = "text/javascript"> 
//Script para incluir en el ComboBox1 cada item chekeado del chkListMateriales
function CheckItem(checkBoxList)
{
    var options = checkBoxList.getElementsByTagName('input');
    var arrayOfCheckBoxLabels= checkBoxList.getElementsByTagName("label");
    var s = "";
    
    for(i=0;i<options.length;i++)
    {
        var opt = options[i];
        if(opt.checked)
        {
            s = s + ", "+ arrayOfCheckBoxLabels[i].innerText; 
        } 
    }
    if(s.length > 0) 
    {       
       s = s.substring(2, s.length); //sacar la primer 'coma'
    }
    var TxtBox = document.getElementById("<%=txtCombo.ClientID%>");       
    TxtBox.value = s;
    document.getElementById('<%=hidVal.ClientID %>').value = s;
}
</script>


<asp:TextBox ID="txtCombo" runat="server" ReadOnly="true" Width="200" Font-Size="X-Small"></asp:TextBox>
<cc1:PopupControlExtender ID="PopupControlExtender111" runat="server" 
    TargetControlID="txtCombo" PopupControlID="Panel111" Position="Bottom" >
</cc1:PopupControlExtender>

<input type="hidden" name="hidVal" id="hidVal" runat="server" />

<asp:Panel ID="Panel111" runat="server" ScrollBars="Vertical" Width="250" Height="150" BackColor="AliceBlue" BorderColor="Gray" BorderWidth="1">
    
    <asp:CheckBoxList ID="chkList" 
        runat="server" 
        Height="150" onclick="CheckItem(this)">                                                                                                                                                                        
    </asp:CheckBoxList>
    
</asp:Panel>


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Argentina Argentina
Systems Eng.

Comments and Discussions