C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How we can select all list box and Deselect All list box using javascript
WhatsApp
Nanhe Siddique
5y
40.6
k
0
1
25
Blog
And when user click Deselect All button then all item of list box deselected like
For these add listbox inside body tag and add two button Select All and Deselect All
asp:ListBox
ID
=
"lstbox"
runat
=
"server"
SelectionMode
=
"Multiple"
Height
=
"150px"
Width
=
"100px"
>
<
asp:ListItem
Value
=
"1"
Text
=
"Class 1"
>
</
asp:ListItem
>
<
asp:ListItem
Value
=
"2"
Text
=
"Class 2"
>
</
asp:ListItem
>
<
asp:ListItem
Value
=
"3"
Text
=
"Class 3"
>
</
asp:ListItem
>
<
asp:ListItem
Value
=
"4"
Text
=
"Class 4"
>
</
asp:ListItem
>
<
asp:ListItem
Value
=
"5"
Text
=
"Class 5"
>
</
asp:ListItem
>
<
asp:ListItem
Value
=
"6"
Text
=
"Class 6"
>
</
asp:ListItem
>
<
asp:ListItem
Value
=
"7"
Text
=
"Class 7"
>
</
asp:ListItem
>
</
asp:ListBox
>
<
button
onclick
=
"selectDeselect('lstbox', true);return false;"
>
Select All
</
button
>
<
button
onclick
=
"selectDeselect('lstbox', false);return false;"
>
Deselect All
</
button
>
And javaScript in head Tag
script>
function
selectDeselect(listid, status) {
var
listb = document.getElementById(listid);
var
len = listb.options.length;
for
(
var
i = 0; i < len; i++) {
listb.options[i].selected = status;
}
}
</script>
And now run the code
It May help Anyone!!
People also reading
Membership not found