A simple example code of asp.net AutoCompleteExtender

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Asp: TextBox ID = "txtTempScenic" runat = "server"> </asp: TextBox>
<Ajax: AutoCompleteExtender ID = "txtTempScenic_AutoCompleteExtender" runat = "server" BehaviorID = "AutoCompleteEx" DelimiterCharacters = "" Enabled = "True" ServicePath = "~ /WebService/AutoComplete. asmx "ServiceMethod =" GetScenic "TargetControlID =" register "CompletionInterval =" 500 "CompletionSetCount =" 20 "EnableCaching =" true "MinimumPrefixLength =" 1 "> </ajax: AutoCompleteExtender>


AutoComplete. asmx
Copy codeThe Code is as follows:
<% @ WebService Language = "C #" CodeBehind = "~ /App_Code/AutoComplete. cs "Class =" AutoComplete "%>


AutoComplete. cs
Copy codeThe Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. Services;
Using System. Data;

/// <Summary>
/// Add by ahuinan
/// </Summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
[System. Web. Script. Services. ScriptService]
Public class AutoComplete: System. Web. Services. WebService
{


Public AutoComplete ()
{

// If you use the designed component, uncomment the following line
// InitializeComponent ();
}

[WebMethod]
Public string HelloWorld ()
{
Return "Hello World ";
}


// Obtain the Scenic Spot
[WebMethod]
Public string [] GetScenic (string prefixText, int count)
{

ET_ERP.BLL.ERP_ScenicArea B _ScenicArea = new ET_ERP.BLL.ERP_ScenicArea ();
String strWhere = "SA_Name like '" + prefixText + "%' AND SA_IsDel = 0 ";

DataSet ds = B _ScenicArea.Select ("top" + count + "SA_Name", strWhere );

Count = ds. Tables [0]. Rows. Count;

String [] array = new string [count];
For (int I = 0; I <count; I ++)
{
Array [I] = ds. Tables [0]. Rows [I] ["SA_Name"]. ToString ();
}

Return array;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.