本文介绍了如何在不使用webservice的情况下解析自动完成文本框和ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了从数据库获取firstname的函数并尝试将该方法用于autotextextender for textbox但是这不起作用。
请帮我解决这个问题?
Methos:
I have created function for get firstname from database and try to use that method into autotextextender for textbox but this is not working.
please help me how to resolve this?
Methos:
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetEmpName(string prefixText)
{
Entities objEntities = new Entities();
List<string> empName = new List<string>();
string ename = "";
var objList = (from i in objEntities.HCM_EMPLOYEE_DETAILS
where i.FIRST_NAME.Contains(prefixText)
select i).ToList();
foreach (var i in objList)
{
ename = i.FIRST_NAME;
empName.Add(ename);
}
return empName;
}
资料来源:
Source:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EmployeeForm.aspx.cs" Inherits="AutoTextboxUserControl.EmployeeForm" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true"> </asp:ScriptManager>
Enter a Employee Name
<asp:TextBox ID="txtProductList" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="GetEmpName"
MinimumPrefixLength="1"
CompletionInterval="0" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtProductList"
ID="autoCompleteExtender1" runat="server" FirstRowSelected = "false" UseContextKey="True">
</cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
推荐答案
[System.Web.Services.WebMethod]
public static List<string> GetEmpName(string prefixText, int count)
而不是
instead of
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetEmpName(string prefixText)
这篇关于如何在不使用webservice的情况下解析自动完成文本框和ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!