欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

不使用web服務(wù)(Service)實(shí)現(xiàn)文本框自動完成擴(kuò)展

 更新時間:2013年04月01日 08:57:22   作者:  
以前寫Ajax 的AutoCompleteExtender功能,都需要寫WCF Service或是Web Service數(shù)據(jù)源,下面的演示,不用寫Service來實(shí)現(xiàn)文本框的AutoCompete extender功能,感興趣的朋友可以參考下哈

以前寫Ajax 的AutoCompleteExtender功能,都需要寫WCF Service或是Web Service數(shù)據(jù)源。但一個系統(tǒng)中,很多文本框都想使用AutoComplete的功能。我們不可能寫很多的Service,比如一些較小的數(shù)據(jù)。我們是否有一個可替換的方法呢?這是肯定的。下面的演示,Insus.NET以不用寫Service來實(shí)現(xiàn)文本框的AutoCompete extender功能。

首先從數(shù)據(jù)庫獲取數(shù),你可以寫SQL語句,或是寫存儲過程,以下是獲取域用戶信息,仿Outlook輸入收件人效果。

在[ActiveDirectoryInfo]表中的信息,是定期與域的活動目錄同步。

復(fù)制代碼 代碼如下:

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 +'''')

在邏輯層,我們寫一個類別,去與數(shù)據(jù)層交互:
復(fù)制代碼 代碼如下:

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];
}
}
}

以上類別中,有一個對象即是BusinessBase
把ScriptManager
復(fù)制代碼 代碼如下:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

或ToolkitScriptManager
復(fù)制代碼 代碼如下:

<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />

拉至網(wǎng)頁。

下圖是html與cs程序,在方法前必須兩行代碼:

復(fù)制代碼 代碼如下:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]


效果:

相關(guān)文章

最新評論