I need to get all selected items of a listbox and then insert inside a int[] array.
int[] status = new int[] { 0 };
foreach (ListItem Status in lstFiltro.Items)
{
if (Status.Selected == true)
{
status[] = Convert.ToInt32(S开发者_C百科tatus.Value);
}
}
With a for-loop you'd want to add items to a list (it'll be easier). Or you could just do this (assuming you're using .Net 3.5+):
using System.Linq;
....
var status = lstFiltro.Items.Where(s => s.Selected)
.Select(s => Convert.ToInt32(s.Value)
.ToArray();
精彩评论