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!!