如何获取所有结果以显示使用下拉列表在页面上显示的不同字段中的值 [英] How Do I Get All The Results For A The Values In A Distinct Field To Display On Page Using A Dropdown

查看:94
本文介绍了如何获取所有结果以显示使用下拉列表在页面上显示的不同字段中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Dropdown中我试图显示来自特定部门的所有新闻



我在数据库中有不同ID的部门........ ...







In my Dropdown im trying to Display all the news from a specific Department

I have Departments with different ids in the database ...........



public List<New>  getNewsType()
    {
        NewsDataContext objNews = new NewsDataContext(); // new instance of class


      var allNews=  objNews.News.GroupBy(x => x.Department).Select(x => x.SingleOrDefault());

      return allNews.ToList();


  private void bindNews()
    {
        linqClass objLinq = new linqClass();

        ListView1.DataSource = objLinq.getNewsType();
        ListView1.DataBind();
        ddl_news.DataSource = objLinq.getNews();
        ddl_news.DataTextField = "Department";
        ddl_news.DataValueField = "Department";
        ddl_news.DataBind();
    }

推荐答案

ICollection<ServiceContract> serviceContract = mapper.MapDALServiceContracts2BAL(objDalServiceContract.getAllServiceContract());
           if (id > 0)
           {

             var sc = serviceContract.GroupBy(m => m.EndDate).Select(g => g.First());

           }







欲了解更多详情,请访问以下链接。 />
http://www.code- sample.com/2014/06/distinct-values-from-list-using-linq.html [ ^ ]


这篇关于如何获取所有结果以显示使用下拉列表在页面上显示的不同字段中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆