问题
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:
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;
}
...
回答2:
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:
来源:https://stackoverflow.com/questions/3140258/select-all-items-in-the-listbox-in-asp-net