asp.net autocompleteextender A simple example code _ Practical Tips

Source: Internet
Author: User
Copy Code code 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= "Txttempscenic" completioninterval= "completionsetcount=" enablecaching= "true" Minimumprefixlength= "1" ></ajax:AutoCompleteExtender>


Autocomplete.asmx
Copy Code code as follows:

<%@ WebService language= "C #" codebehind= "~/app_code/autocomplete.cs" class= "AutoComplete"%>


AutoComplete.cs
Copy Code code 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 the use of ASP.net AJAX to invoke this Web service from a script, uncomment the downlink.
[System.Web.Script.Services.ScriptService]
public class AutoComplete:System.Web.Services.WebService
{


Public AutoComplete ()
{

If you are using a design component, uncomment it to follow the line
InitializeComponent ();
}

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


Access to scenic spots
[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;
}
}

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.