相关疑难解决方法(0)

使用Linq将ListBox项值转换为int

我使用ListBox在数据库中显示表的内容.每个列表框项都填充了Text属性设置为友好名称,Value属性设置为唯一ID列.数据库结构可能类似于以下内容:

CREATE TABLE GENERIC { FRIENDLY_NAME TEXT, ID INT }
Run Code Online (Sandbox Code Playgroud)

我尝试使用LINQ将列表框的项目转换为int []差不多一个小时,最终失败了.区分所选项目和未选择项目也很重要.这是我最后写的:

System.Collections.Generic.LinkedList<int> 
            selected = new LinkedList<int>(), 
            notSelected = new LinkedList<int>();

        foreach (ListItem item in PhotoGalleryEdit_PhotoShoots.Items)
        {
            if (item.Selected)
                selected.AddFirst(Convert.ToInt32(item.Value));
            else
                notSelected.AddFirst(Convert.ToInt32(item.Value));
        }

 int []arraySelected = selected.ToArray();
 int []arrayNotSelected = notSelected.ToArray();
Run Code Online (Sandbox Code Playgroud)

任何人都可以在LINQ中展示如何做到这一点?

(我在C#中编写了所有代码,但用VB编写的任何答案都非常受欢迎)

c# linq asp.net listbox asp.net-3.5

2
推荐指数
1
解决办法
9902
查看次数

标签 统计

asp.net ×1

asp.net-3.5 ×1

c# ×1

linq ×1

listbox ×1