使用 LINQ 将数据库中没有重复项的值绑定到下拉列表中
我在 ASP.NET 代码隐藏中使用 LINQ 将值绑定到下拉列表时遇到一个小问题。
var clientquer = from i in Entity.New_Bank select i;
//var q = (from s in names
// select s).Distinct();
// var getlendername = (from db in mortgageentity.New_Lender group db by db.Bank_Name into t select t.Key).ToList();
if (clientquer.Count() > 0)
{
ddlbankname.DataSource = clientquer.ToList();
ddlbankname.DataValueField = "Bank_ID2";
ddlbankname.DataTextField = "Bank_Name";
ddlbankname.DataBind();
}
它与重复值绑定,但我不想绑定重复值。我试图通过使用 group by 子句来解决这个问题,但它不起作用。
这怎么能做到呢?
I have a small issue binding the values into a dropdown using LINQ in ASP.NET code-behind.
var clientquer = from i in Entity.New_Bank select i;
//var q = (from s in names
// select s).Distinct();
// var getlendername = (from db in mortgageentity.New_Lender group db by db.Bank_Name into t select t.Key).ToList();
if (clientquer.Count() > 0)
{
ddlbankname.DataSource = clientquer.ToList();
ddlbankname.DataValueField = "Bank_ID2";
ddlbankname.DataTextField = "Bank_Name";
ddlbankname.DataBind();
}
It is binding with duplicate values, but I don't want bind duplicate values. I'm trying to solve this by using a group by clause, but it is not working.
How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
然后像平常一样绑定你的下拉菜单。
Try this:
Then bind your dropdown as normal.