In the past, the AutoCompleteExtender function of Ajax was written to the WCF Service or Web Service data source. However, in a system, many text boxes want to use the AutoComplete function. We cannot write many services, such as small data. Is there an alternative? This is for sure. In the following example, Insus. NET implements the AutoCompete extender function of the text box without writing services.
First, you can obtain the number from the database. You can write an SQL statement or a stored procedure. The following describes how to obtain the domain user information, similar to the effect of the recipient input by Outlook.
Information in the [ActiveDirectoryInfo] Table is regularly synchronized with the Active Directory of the domain.
Copy codeThe Code is 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 logic layer, we write a category to interact with the data layer:
Copy codeThe Code is 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
{
Businimap4 objbusinimap4 = new businimap4 ();
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 objbusinimap4. GetDataToDataSet ("usp_ActiveDirectoryInfo_GetDisplayNameByPrefixText", parameter). Tables [0];
}
}
}
In the preceding category, an object is businworksheet.
Set ScriptManager
Copy codeThe Code is as follows:
<Asp: ScriptManager ID = "ScriptManager1" runat = "server"> </asp: ScriptManager>
Or ToolkitScriptManager
Copy codeThe Code is as follows:
<AjaxToolkit: ToolkitScriptManager ID = "ToolkitScriptManager1" runat = "server"/>
Pull to the webpage.
It is an html and cs program. There must be two lines of code before the method:
Copy codeThe Code is as follows:
[System. Web. Services. WebMethod]
[System. Web. Script. Services. ScriptMethod]
Effect: