本文介绍了从数据库加载数据时,如何重复短语不显示到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

如何从数据库加载数据时重复短语不显示控制下拉列表

请帮助我

我的代码是

hello
How do I repeat phrases when loading data from the database don't show to control of drop down list
plz help me
my code is

var JensKakhat = db.ItemProducts.Where(c => c.ForProductId == DdlProduct.SelectedValue.ToString()).ToList();

int count3 = JensKakhat.Count();
if (count3 <= 0)
    PnlTypePaper.Visible = false;
else
    PnlTypePaper.Visible = true;

DdlTypePaper.DataSource = JensKakhat;
DdlTypePaper.DataTextField = "ItemNine";
DdlTypePaper.DataValueField = "Id";
DdlTypePaper.DataBind();

推荐答案

var  result = JensKakhat.GroupBy(g => g.Id)
                         .Select(g => g.First())
                         .ToList();
PnlTypePaper.Visible = result.Any(); 

DdlTypePaper.DataSource = result;
DdlTypePaper.DataTextField = "ItemNine";
DdlTypePaper.DataValueField = "Id";
DdlTypePaper.DataBind();


这篇关于从数据库加载数据时,如何重复短语不显示到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:23