【问题标题】:AjaxControlToolkit AutoCompleteExtender is not displaying suggestionsAjaxControlToolkit AutoCompleteExtender 不显示建议
【发布时间】:2018-09-16 04:10:16
【问题描述】:

我在 asp.net 中使用 AutoCompleteExtender 来获取基于令牌(empno)的名称和指定。 这是从数据库中提取的,我可以在 Chrome Dev-tools 的网络选项卡中看到它。但它不会呈现为建议列表。

我对代码的尝试:

<div class="modal-body">                        
                     <div class="form-group">
                        <label for="pToken">Token</label>
                         <asp:TextBox ID="pToken" runat="server" CssClass="form-control" placeholder="Enter Token No" />                           
                         <ajaxcontrol:AutoCompleteExtender runat="server" 
                                    ID="acToken" TargetControlID="pToken" MinimumPrefixLength="3"
                                    EnableCaching="true" FirstRowSelected="false" 
                                    ServiceMethod="getPatients" ServicePath="CheckPatientDetails.aspx"
                                    CompletionSetCount="6" DelimiterCharacters="|"
                                    CompletionListItemCssClass="AutoCompleteExtender_CompletionListItem"
                                    CompletionListHighlightedItemCssClass="AutoCompleteExtender_HighlightedItem"
                                    CompletionListCssClass="AutoCompleteExtender_CompletionList">
                          </ajaxcontrol:AutoCompleteExtender>
                     </div>
                    <div class="form-group">
                        <label for="pName">Name</label>                            
                        <asp:TextBox ID="pName" runat="server" CssClass="form-control" placeholder="Enter patient name" required />
                    </div>
                    <div class="form-group">
                        <label for="pDesig">Designation</label>                            
                        <asp:TextBox ID="pDesig"  runat="server" CssClass="form-control" placeholder="Enter designation" />
                    </div>
                    <div class="form-group">
                        <label for="pType">Type</label>                            
                        <asp:DropDownList ID="pType" runat="server" CssClass="form-control" required>
                            <asp:ListItem Value="E" Selected="True">Employee</asp:ListItem>
                            <asp:ListItem Value="I">In Patient</asp:ListItem>
                            <asp:ListItem Value="O">Out Patient</asp:ListItem>                        
                            <asp:ListItem Value="X">Others</asp:ListItem>                                
                        </asp:DropDownList>                            
                    </div>

后端代码如下:

[WebMethod]
    [System.Web.Script.Services.ScriptMethod()]
    public static List<Patient> getPatients(string prefixText, int count)
    {
        List<Patient> patientList = new List<Patient>();
        OracleConnection con = null;
        OracleDataReader odr = null;

        string query = "select nvl(emp.empid,'') token,DECODE(SHORTNAME,NULL,FIRSTNAME,SHORTNAME)  name,DESIGSHORT desigdesc" +
                        " from employee emp join designation desig  on (emp.desigcode = desig.desigcode and desig.isactive = 'Y') " +
                        " where empid like '%" + prefixText + "%' and emp.EMPSTATUS = 'A' order by empid";
        try
        {
            con = getHRMSConnection();
            con.Open();
            using (con)
            {
                using (OracleCommand cmd = new OracleCommand(query, con))
                {
                    odr = cmd.ExecuteReader();
                    Patient patient = null;
                    while (odr.Read())
                    {
                        patient = new Patient();
                        patient.setToken(Convert.ToString(odr["token"]));
                        patient.setName(Convert.ToString(odr["name"]));
                        patient.setDesignation(Convert.ToString(odr["desigdesc"]));
                        patientList.Add(patient);
                    }

                }
            }
        }
        catch (Exception ex)
        {

        }
        return patientList;
    }

【问题讨论】:

  • 打开一个新页面,先尝试示例自动扩展器以获取更多知识。这将使您了解发生了什么问题。我建议你使用这个链接来实现c-sharpcorner.com/UploadFile/57a357/…。因为很难说出您的代码有什么问题。希望对你有帮助
  • 我已经尝试过,它现在正在获取数据。可能 b 数据表的概念在这里工作正常。但仍然不相信。

标签: asp.net c#-4.0 ajaxcontroltoolkit autocompleteextender


【解决方案1】:

您所面临的问题有很多原因。从基本检查服务路径是否正确开始。

其次,您是否在获取数据的函数上方声明了 [webmethod]。

【讨论】:

  • 我已经用被调用的后端方法更新了这个问题。在放置断点时,函数正在执行。还将服务器的响应放入快照中。因此正在获取数据但未显示。
【解决方案2】:

现在任务已完成,我正在正确呈现自动完成功能。为以后可能会参考此内容的人发帖。

我使用此链接来获取在模态上呈现的自动完成功能。 Autocomplete extender not working inside modal popup extender

现在我的模态体是

 <div class="modal-body">             
                     <div class="form-group">             

                    <asp:AutoCompleteExtender ServiceMethod="GetSearch" MinimumPrefixLength="2" CompletionInterval="10"  
                        EnableCaching="false" CompletionSetCount="10" TargetControlID="pToken" ID="AutoCompleteExtender2"  
                        runat="server" FirstRowSelected="false" CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem" 
                        CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem">  
                    </asp:AutoCompleteExtender>  
                    <label for="pToken">Token</label>                        
                    <asp:TextBox ID="pToken" runat="server"  CssClass="form-control" placeholder="Enter Token No"/>                

                     </div>
                    <div class="form-group">
                        <label for="pName">Name</label>                            
                        <asp:TextBox ID="pName" runat="server" CssClass="form-control" placeholder="Enter patient name" required />
                    </div>
                    <div class="form-group">
                        <label for="pDesig">Designation</label>                            
                        <asp:TextBox ID="pDesig"  runat="server" CssClass="form-control" placeholder="Enter designation" />
                    </div>
                    <div class="form-group">
                        <label for="pType">Type</label>                            
                        <asp:DropDownList ID="pType" runat="server" CssClass="form-control" required>
                            <asp:ListItem Value="E" Selected="True">Employee</asp:ListItem>
                            <asp:ListItem Value="I">In Patient</asp:ListItem>
                            <asp:ListItem Value="O">Out Patient</asp:ListItem>                        
                            <asp:ListItem Value="X">Others</asp:ListItem>                                
                        </asp:DropDownList>                            
                    </div>
                </div>

服务器端代码是:

[WebMethod]
    [System.Web.Script.Services.ScriptMethod()]
    public static List<string> GetSearch(string prefixText, int count)
    {

            OracleConnection con = null;
            OracleDataAdapter oda = null;
            DataTable dt;
            prefixText = prefixText.ToLower();
            DataTable Result = new DataTable();
            List<string> Output = new List<string>();

            string str = "select nvl(emp.empid,'') ||'('||DECODE(SHORTNAME,NULL,FIRSTNAME,SHORTNAME)||','|| DESIGSHORT ||')' employee" +
                           " from employee emp join designation desig  on (emp.desigcode = desig.desigcode and desig.isactive = 'Y') " +
                           " where lower(empid) like '%" + prefixText + "%' and emp.EMPSTATUS = 'A' order by empid";
            con = getHRMSConnection();
            using (con)
            {
            try
            {
                con.Open();
                oda = new OracleDataAdapter(str, con);

                dt = new DataTable();
                oda.Fill(dt);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Output.Add(dt.Rows[i][0].ToString());
                }

            }
            catch (Exception ex)
            {

            }
        }

        return Output;
    }

【讨论】:

    猜你喜欢
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多