views:

42

answers:

2

if checkbox is clicked i need to select all items in the listbox in asp.net...

how to show the items all selected in listbox once the 'selectall' checkbox is clicked

+1  A: 

You can use the attribute OnClientClick with your ASP.NET Listbox to fire a javascript function that selects all items. If your ASP.NET Listbox runs on the server, you should refer it in your Javascript using:

<%= MyListbox.ClientID %>

Sander Pham
+1  A: 

In the CheckedChanged event handler of the checkbox, iterate through all the items of the list and set the Selected property for all as true. You also need to make sure that the multi selection is enabled on your listbox. Use the following to do that:

...
for(int i=0;i<ListBox1.Items.Count;i++)
{
    ListBox1.Items[i].Selected = true;
}
...
Prashant