Linq 自动完成扩展程序未按字母顺序排序
我在Web服务中使用LINQ,它在文本框上创建自动完成函数。我已经做到了,但不幸的是,结果没有按照我预期的顺序填充,例如,如果我搜索的饮料是从carl开始的,我希望先是carling,然后是carlsberg,但事实并非如此 正在使用的Web服务是:Linq 自动完成扩展程序未按字母顺序排序,linq,web-services,autocomplete,Linq,Web Services,Autocomplete,我在Web服务中使用LINQ,它在文本框上创建自动完成函数。我已经做到了,但不幸的是,结果没有按照我预期的顺序填充,例如,如果我搜索的饮料是从carl开始的,我希望先是carling,然后是carlsberg,但事实并非如此 正在使用的Web服务是: public string[] GetProdDesSearch(string prefixText, int count) { try { ReportingService.Pro
public string[] GetProdDesSearch(string prefixText, int count)
{
try
{
ReportingService.ProductsDataContext dbac = new ReportingService.FinalProductsDataContext();
return dbac.FINALPRODUCTSNEWDEMOs
.Where(r => r.MemberId == HttpContext.Current.Session["MemberKey"].ToString() && r.IDDesc.Contains(prefixText))
.OrderBy(r => r.UnitDescription)
.Select(r => r.IDDesc)
.Distinct()
.Take(count)
.ToArray();
}
catch (Exception)
{
return null;
}
}
}
.net的详细信息如下:
<asp:TextBox ID="tbxProdAC" runat="server"
style="z-index: 1; left: 200px; top: 460px; position: absolute; height: 20px; width: 345px;"
CssClass="completionList2" AutoPostBack="True"
ontextchanged="tbxProdAC_TextChanged"></asp:TextBox>
<cc1:AutoCompleteExtender ID="tbxProdAC_AutoCompleteExtender" runat="server"
DelimiterCharacters="" Enabled="True"
ServicePath="~/Reporting/GetProd.asmx"
ServiceMethod="GetProdDesSearch"
TargetControlID="tbxProdAC"
CompletionInterval="50" CompletionSetCount="50"
MinimumPrefixLength="3"
onclientpopulating="ShowImage"
onclientpopulated="HideImage"
CompletionListCssClass="completionList2">
</cc1:AutoCompleteExtender>
.completionList2 {font-family: Trebuchet MS;font-size:11px; border:solid 1px #444444;margin:0px;padding:2px;height: 395px;
overflow:auto; background-color:White;
z-index: 1;
left: 200px;
top: 310px;
position: absolute;
width: 1496px;
}
如果有人能以我的方式指出错误,我将不胜感激。您正在按UnitDescription排序,但prefixText上的约束和最终选择的项都是IDDesc。您应该使用哪一个并不明显,但我认为您应该保持一致——要么按IDDesc排序,要么让您的Contains和Select调用也使用UnitDescription。您是按UnitDescription排序的,但prefixText上的约束和最后选择的项都是IDDesc。你应该使用哪一种并不明显,但我认为你应该保持一致——要么按IDDesc排序,要么让你的Contains和Select调用也使用UnitDescription。我找到了答案
在Web服务中的my LINQ查询中,应将distinct放在orderby之前:
return dbac.FINALPRODUCTSNEWDEMOs
.Where(r => r.MemberId == HttpContext.Current.Session["MemberKey"].ToString() && r.IDDesc.Contains(prefixText))
.Distinct()
.OrderBy(r => r.IDDesc)
.Select(r => r.IDDesc)
.Take(count)
.ToArray();
我找到了答案
在Web服务中的my LINQ查询中,应将distinct放在orderby之前:
return dbac.FINALPRODUCTSNEWDEMOs
.Where(r => r.MemberId == HttpContext.Current.Session["MemberKey"].ToString() && r.IDDesc.Contains(prefixText))
.Distinct()
.OrderBy(r => r.IDDesc)
.Select(r => r.IDDesc)
.Take(count)
.ToArray();
很多道歉Jon,那是我在“玩”,看看使用unitdescription是否有什么不同。当我按IDDesc订购时,也会出现同样的情况,即产品列表排序不正确。从几行来看,似乎没有实际进行排序。看起来它只是在不进行排序的情况下收回数据。Jon,这是我在“玩”,看看使用unitdescription是否有什么不同。当我按IDDesc排序时,也会出现同样的情况,即产品列表排序不正确。从几行来看,似乎它只是在不排序的情况下收回数据。