1

私は次のcombo ようなデータを入力する DropDownList を持っています:

cboTypeOfMaterial.DataSource = (from tom in context.MaterialTypes
                                where tom.IsActive == true
                                select tom.Name).Distinct().ToList();

問題は、この DropDownList を検索に使用し、空の行などを 1 つ持ちたいことです。ユーザーがこのデータを特定の検索に含めたくない場合は、リストを空のままにするために使用できる余分な行を 1 つだけ使用します。

4

3 に答える 3

1

これを試して :

IList<String> materialTypes = (from tom in context.MaterialTypes
                                where tom.IsActive == true
                                select tom.Name).Distinct().ToList();
materialTypes.Insert(0, "-- Please Select --");
cboTypeOfMaterial.DataSource = materialTypes;
于 2013-02-22T07:34:37.920 に答える
1
var list = (from tom in context.MaterialTypes
            where tom.IsActive == true
            select tom.Name).Distinct().ToList();

list.Insert(0, "");
cboTypeOfMaterial.DataSource = list;

これにより、リストに空白の項目が追加されます。

于 2013-02-22T07:35:23.257 に答える
1

最初にリストに空の要素を追加してから、コンテキストからアイテムを追加するだけでよいと思います

Example:

cboTypeOfMaterial.DataSource = new string[] { string.Empty }
                               .Concat(from tom in context.MaterialTypes
                                       where tom.IsActive == true
                                       select tom.Name).Distinct().ToList();
于 2013-02-22T07:39:22.163 に答える