AutoCompleteExtender不显示结果

时间:2012-07-03 19:21:07

标签: c# asp.net ajaxcontroltoolkit

我想使用AjaxToolkit AutoCompleteExtender。我的WebService被触发,如果我在返回的值上放置一个断点,我可以看到有返回的数据。但是,AutoCompleteExtender未显示结果。

我已经读过这个stackoverflow线程:AutoCompleteExtender is firing, webservice is returning results, but these are not being displayed

但是,答案并没有解决我遇到的问题。

这是我的代码:

ASPX

<asp:ToolkitScriptManager ID="asm" runat="server" EnablePageMethods="true" EnablePartialRendering="true"></asp:ToolkitScriptManager>
<asp:UpdatePanel ID="upApprovedBy" runat="server">
    <ContentTemplate>
        <asp:TextBox id="txtApprovedBy" runat="server" AutoComplete="Off"></asp:TextBox>
        <asp:AutoCompleteExtender 
            runat="server" 
            ID="ac_txtApprovedBy"  
            CompletionInterval="500"
            TargetControlID="txtApprovedBy"
            ServiceMethod="SearchWinUsers"
            CompletionSetCount="20"                                                                                                                         
            MinimumPrefixLength="2" 
        >
        </asp:AutoCompleteExtender>
    </ContentTemplate>
</asp:UpdatePanel>

ASPX.CS

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] SearchWinUsers(string prefixText, int count)
{
    logic common = new logic();
    string[] SelectedApprovers = new string[0];
    try
    {
        DataTable dt = new DataTable();
        string sql = "SELECT TOP(" + count + ") FirstName + ' ' + LastName AS DisplayName FROM USERSTABLENAME WHERE (IsDeActivated = 0) AND ((FirstName LIKE '%" + prefixText + "%') OR (LastName LIKE '%" + prefixText + "%')) ORDER BY FirstName";
        dt = common.getDataTable(sql);
        SelectedApprovers = new string[dt.Rows.Count];
        int i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            SelectedApprovers.SetValue(dr["DisplayName"].ToString(), i);
            i++;
        }
        dt.Dispose();
    }
    catch (Exception ex)
    {
        common.alert("Error in page.location.<br>ERROR=" + ex.Message);
    }

    return SelectedApprovers;
}

任何建议都将不胜感激!

我应该提一下,我的ASPX代码段中的代码存在于此层次结构中:Page&gt; TabContainer&gt; TabPanel&gt; FormView&gt;这个代码在这里生活

1 个答案:

答案 0 :(得分:0)

终于有了工作!!!

我将web服务从* .ASPX.CS移到* .ASMX

这解决了我遇到的问题。

如果您遇到同样的问题,请查看本教程。它让我朝着正确的方向前进!

http://www.codeproject.com/Articles/201099/AutoComplete-With-DataBase-and-AjaxControlToolkit#