var result = from u in db.country
                     group u.continent by u.continent into u
                     select new
                         {
                             u.Key                         };
        
        DropDownList1.DataSource = result;
        DropDownList1.DataBind();
我的代码是这样写的,但是这样运行后DropDownList中显示的是 key=亚洲,key=美洲请问该如何改,让它只显示亚洲,美洲呢。刚开始接触linq,谢谢各位了

解决方案 »

  1.   

    DropDownList1.DataTextField = "编号";
    DropDownList1.DataValueField = "姓名";
    var result = from u in db.country
                         group u.continent by u.continent into u
                         select new
                             {
                                 key = u.Key                         };
            
    DropDownList1.DataSource = result;
    DropDownList1.DataTextField = "key";
    DropDownList1.DataValueField = "key";DropDownList1.DataBind();