Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have select all button and i have some names in checked list box if i click select all button then all names in checked list box have to select............so
first i have to select all items after that those items should be move to listbox.

thank u
Posted
Updated 25-Sep-14 1:13am
v5
Comments
BillWoodruff 24-Sep-14 2:47am    
Originally this question asked about "moving," ... and it has some answers based on that ... and now it asks about multiple selecting on a button click.

Member 11065510, please clarify what you are asking. Are there one, or two, ListBoxes ? Are you "moving" ListBox Items, or trying to select them all in one ListBox ?
Member 11065510 24-Sep-14 2:55am    
first i have to select all items after that those items should be move to listbox.
BillWoodruff 24-Sep-14 3:10am    
Okay, please edit your original question so this is clear for everyone.
BillWoodruff 24-Sep-14 4:10am    
Please edit your question so it's clear exactly how many Controls of exactly what type you are talking about.

If you are using 'CheckedListBox, do you know that Control does not support multiple selection ?

It sounds like you have one CheckedLIstBox, and one ListBox: you want to move Items from the CheckedListBox to the ListBox ... correct ?
Member 11065510 24-Sep-14 4:17am    
yes

try like below
C#
List<string> lstString = new List<string>();
foreach (ListItem li1 in checkedListBoxId.CheckedItems)
                {
                    if (li1.Selected == true)
                    {
                        lstString.Add(li1.Text);
                    }
                }

secondListBoxId.DataSource = lstString.Add;

Hope this helps
 
Share this answer
 
assuming, you want to move selected items of Listbox1 to Listbox2.
Function for moving:
C#
private void MoveListBoxItems(ListBox source, ListBox destination)
{
    ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
    foreach (var item in sourceItems)
    {
        destination.Items.Add(item);
    }
    while (source.SelectedItems.Count > 0)
    {
        source.Items.Remove(source.SelectedItems[0]);
    }
}


Button Click for call moving function

C#
private void first2second_Click(object sender, EventArgs e)
{
    MoveListBoxItems(FirstListbox, LastListbox);
}
 
Share this answer
 
v2
XML
foreach (ListItem li1 in checkedListBoxId.CheckedItems)
                {
                     (li1.Selected = true)
                }


I think is what you want?
 
Share this answer
 
Beter you try this using javascript

code for Check box

XML
<asp:CheckBox ID="cbAll" runat="server" Text="Select All" onclick="CheckAll();" BackColor="Aqua" />
           <asp:CheckBoxList ID="cbList" runat="server" ValidationGroup="VGroup" onclick="UnCheckAll();">
               <asp:ListItem Value="1">Asp.net</asp:ListItem>
               <asp:ListItem Value="2">C#.net</asp:ListItem>
               <asp:ListItem Value="3">Vb.net</asp:ListItem>
               <asp:ListItem Value="4">Oracle</asp:ListItem>
               <asp:ListItem Value="5">SqlServer</asp:ListItem>
               <asp:ListItem Value="6">Sharepoint</asp:ListItem>


Java Script
<pre lang="cs"><script language="javascript">
       function CheckAll() {
           var intIndex = 0;
           var rowCount = document.getElementById('cbList').getElementsByTagName("input").length;
           for (i = 0; i < rowCount; i++) {
               if (document.getElementById('cbAll').checked == true) {
                   if (document.getElementById("cbList" + "_" + i)) {
                       if (document.getElementById("cbList" + "_" + i).disabled != true)
                           document.getElementById("cbList" + "_" + i).checked = true;
                   }
               }
               else {
                   if (document.getElementById("cbList" + "_" + i)) {
                       if (document.getElementById("cbList" + "_" + i).disabled != true)
                           document.getElementById("cbList" + "_" + i).checked = false;
                   }
               }
           }
       }

       function UnCheckAll() {
           var intIndex = 0;
           var flag = 0;
           var rowCount = document.getElementById('cbList').getElementsByTagName("input").length;
           for (i = 0; i < rowCount; i++) {
               if (document.getElementById("cbList" + "_" + i)) {
                   if (document.getElementById("cbList" + "_" + i).checked == true) {
                       flag = 1;
                   }
                   else {
                       flag = 0;
                       break;
                   }
               }
           }
           if (flag == 0)
               document.getElementById('cbAll').checked = false;
           else
               document.getElementById('cbAll').checked = true;

       }
   </script></pre>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900