none
代码运行问题 RRS feed

  • 问题

  • 各位大神:
    我想知道为什么下面这段代码运行不了。
    我想在给下拉框绑定值之前进行排序。
    代码
        DropDownList1.DataSource = (from d in dbcontext.UserInfo
                                              orderby d.Id

                                              select new {d.Id}).Distinct().ToList();

    万分感谢!

    2016年10月31日 0:34

全部回复

  • 你好,

    我建议可以把Distinct()方法放在orderby ()之前。

    像下面这样:

    var data = (from d in dbcontext.Tyres
                          select new {d.Id})
                         .Distinc()
    		     .OrderBy(d => d.Id);
    
    ddlMake.DataSource = data.ToList();
    ddlMake.DataBind();

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2016年10月31日 8:38
  • 你好 Anne_Wx,

    这个问题解决了吗?现在有什么进展? 谢谢!

    Best regards,

    yanjin 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2016年11月11日 9:47