开发者

create int[] listbox multiselect

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜