开发者

create int[] listbox multiselect

开发者 https://www.devze.com 2023-03-25 03:47 出处:网络
I need to get all selected items of a listbox and then insert inside a int[] array. int[] status = new int[] { 0 };

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

精彩评论

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

关注公众号