Click here to Skip to main content
16,016,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used this code for select all items in listbox when click the checkbox.

in page_load
listbox1.Attributes.Add("onclick", "javascript: selectall();")


in javascript:
JavaScript
function selectall()
     {
     //var sel=document.getElementById('cb_selall');
     for(i=0; i<document.form1.li_mana_cards.options.length; i++)
     {
       document.form1.li_mana_cards.options[i].selected = true;
     }
     }

From the OP:
"I want to deselect all items in listbox when i click checkbox. I dont know how to write code for this process. If u know plz help me."
Posted
Updated 17-Apr-11 22:15pm
v6
Comments
Jayanthi-SE 18-Apr-11 1:57am    
If anybody know solution to this pbm plz help me.
OriginalGriff 18-Apr-11 2:00am    
And your question is?
Jayanthi-SE 18-Apr-11 3:10am    
I used this code for select all items in listbox when click the checkbox.

in page_load
listbox1.Attributes.Add("onclick", "javascript: selectall();")

In source:
function selectall() { //var sel=document.getElementById('cb_selall'); for(i=0; i
OriginalGriff 18-Apr-11 3:20am    
And you still have to explain what problem you are getting: edit your question and explain your problem - not what you are doing, what is not working...
Jayanthi-SE 18-Apr-11 4:09am    
I want to deselect all items in listbox when i click checkbox. I dont know how to write code for this process. If u know plz help me.

If the code you have given for selecting the items is working, why not change it: Rename it to "deselectall" and replace "true" with "false"...
 
Share this answer
 
http://forums.asp.net/t/1138169.aspx/1[^]

I hope the above information will be helpful.
 
Share this answer
 
I wrote this coding to select and deselect all items in listbox when click checkbox. Its working well. Thanks to all.

Javascript:

C#
function selectall(cb_selall)
     {

     if (cb_selall.checked)
       {

         for(i=0; i<document.form1.li_mana_cards.options.length; i++)
            {
               document.form1.li_mana_cards.options[i].selected = true;
            }
            }
     else
     {

     for(i=0; i<document.form1.li_mana_cards.options.length; i++)
            {
               document.form1.li_mana_cards.options[i].selected = false;
            }

      }

           }


Page Load:

cb_red_inac.Attributes.Add("onclick", "javascriptselectall(this);")
 
Share this answer
 
v2

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