The Autocompleteextender feature, which used to write Ajax, requires a WCF service or a Web service data source. But in a system, many text boxes want to use the AutoComplete function. We can't write a lot of service, like some smaller data. Do we have a way to replace it? That's for sure. The following demo, insus.net to implement the Autocompete extender function of a text box without writing a service.
First get the number from the database, you can write SQL statements, or write stored procedures, the following is to get the domain user information, imitation Outlook enter the recipient effect.
The information in the [Activedirectoryinfo] table is periodically synchronized with the Active Directory of the domain.
Copy Code code as follows:
Usp_activedirectoryinfo_getdisplaynameforservice
SET ANSI_NULLS on
Go
SET QUOTED_IDENTIFIER ON
Go
-- =============================================
--Author:Insus.NET
--Create date:2013-03-28
--description:get dissplay name Form Web Service
-- =============================================
CREATE PROCEDURE [dbo]. [Usp_activedirectoryinfo_getdisplaynameforservice]
(
@PrefixText NVARCHAR (MAX),
@Count INT
)
As
DECLARE @W NVARCHAR (MAX) = @PrefixText + '% '
EXECUTE (' SELECT top (' + @Count + ') [DisplayName] from [dbo].[ Activedirectoryinfo] WHERE [displayName] like ' + @w + ' ')
At the logical level, we write a category to interact with the data tier:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Data;
Using System.Linq;
Using System.Web;
<summary>
Summary description for Activedirectoryinfo
</summary>
Namespace Insus.net
{
public class Activedirectoryinfo
{
Businessbase objbusinessbase = new Businessbase ();
Public Activedirectoryinfo ()
{
//
Todo:add constructor Logic here
//
}
Public DataTable GetDisplayName (string prefixtext,int count)
{
Parameter[] Parameter = {
New Parameter ("@PrefixText", Sqldbtype.nvarchar,-1,prefixtext),
New Parameter ("@Count", Sqldbtype.int,4,count)
};
Return Objbusinessbase.getdatatodataset ("Usp_activedirectoryinfo_getdisplaynamebyprefixtext", parameter). Tables[0];
}
}
}
One of the objects in the above category is Businessbase
Put ScriptManager
Copy Code code as follows:
<asp:scriptmanager id= "ScriptManager1" runat= "Server" ></asp:ScriptManager>
or Toolkitscriptmanager
Copy Code code as follows:
<ajaxtoolkit:toolkitscriptmanager id= "ToolkitScriptManager1" runat= "Server"/>
Pull to the Web page.
The following figure is the HTML and CS program, which requires two lines of code before the method:
Copy Code code as follows:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
Effect: