我使用网络服务使用自动填充功能。在我的网络服务中,我使用的是LDS。
问题是当我尝试这段代码时:
这是我的UI代码,它在Default.aspx中调用webservice:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path ="WebService1.asmx" />
</Services>
</asp:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
DelimiterCharacters="" Enabled="True" ServicePath ="WebService1.asmx" ServiceMethod="ReturnEntity" EnableCaching="true" TargetControlID="TextBox1" CompletionSetCount ="1">
</asp:AutoCompleteExtender>
这是我的WebService文件(webservice1.asmx)
[WebMethod]
public string[] ReturnEntity(string prefixText, int count)
{
List<string> responses = new List<string>();
for (int i = 0; i < count; i++)
responses.Add(prefixText + (char)(i + 65));
return responses.ToArray();
}
然后它正在运作。但是,我正在研究这段代码而且它无法正常工作......
[WebMethod]
public string[] ReturnEntity(string prefixText)
{
using (DataClasses1DataContext search = new DataClasses1DataContext())
{
string[] fullText = (from n in search.Entities
where n.Name.StartsWith(prefixText)
select n.Name).ToArray();
return fullText;
}
}
当我尝试在浏览器中运行web服务并传递一些参数时,它会向我显示这些:
<?xml version="1.0" encoding="utf-8" ?>
- <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<string>Starr</string>
<string>Sally Jeans</string>
<string>Steven Kline</string>
<string>Steven Goldberg</string>
</ArrayOfString>
这不会返回任何结果。我只是想从我的表中显示实体列表,列名称是'Name'。
无法弄明白:(
答案 0 :(得分:1)
尝试使用StartsWith并传入StringComparison
var result = from n in search.Entities
where n.Name.StartsWith(prefixText,
StringComparison.InvariantCultureIgnoreCase)
select n.Name;
return result.ToArray();
如果仍然在调用的上下文中,您可以使用ToLower()
var result = from n in search.Entities
where n.Name.ToLower().StartsWith(prefixText.ToLower())
select n.Name;
return result.ToArray();