select all items in the listbox in asp.net

自古美人都是妖i 提交于 2019-12-10 22:34:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!