Automatic Input Using Web Services

Source: Internet
Author: User
Automatic Input Using Web Services

The Web Service is used to automatically complete input. Front-End Interface:

 

Code

<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>

<Ajaxtoolkit: autocompleteextender id = "autocompleteextender3" runat = "server" enabled = "true"
Targetcontrolid = "textbox1"
Servicepath = "/lscomplete. asmx"
Servicemethod = "getcompletedepart"
Completioninterval = "500"
Completionsetcount = "10"
Minimumprefixlength = "1">
</Ajaxtoolkit: autocompleteextender>

 

Background code:

Create a Web Service:

 

Code

Using system;
Using system. Web;
Using system. collections;
Using system. Web. Services;
Using system. Web. Services. Protocols;

Using system. Data;
Using system. Data. sqlclient;
Using system. configuration;

/// <Summary>
/// Summary of lscomplete
/// </Summary>
[WebService (namespace = "http://tempuri.org/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
[System. Web. Script. Services. scriptservice]
Public class lscomplete: system. Web. Services. WebService {

Public lscomplete (){

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

Private Static string [] autocompletewordlist = NULL;
[Webmethod]
Public String [] getcompletedepart (string prefixtext, int count)
{
// If the array is empty
If (autocompletewordlist = NULL)
{
// Read the database content

String connectionstring = configurationsettings. etettings ["sqlconnectionstring"];
Sqlconnection myconn = new sqlconnection (connectionstring );
Myconn. open ();

// Sqldataadapter da = new sqldataadapter ("select region name from departinfo where region name like '" + prefixtext + "% 'order by region name", Conn );

String mysel = "select title from [Table name] Where rtrim (field) like '%" + prefixtext + "% '";
Sqldataadapter adpt = new sqldataadapter (mysel, myconn );

Dataset DS = new dataset ();
Adpt. Fill (DS );
// Read the data of the content file to a temporary Array
String [] temp = new string [Ds. Tables [0]. Rows. Count];
Int I = 0;
Foreach (datarow DR in DS. Tables [0]. Rows)
{
Temp [I] = Dr ["field"]. tostring (). Trim ();
I ++;
}
// Assign the content of the temporary array to the returned array
Autocompletewordlist = temp;
If (myconn. State = connectionstate. open)
Myconn. Close ();
}
String [] returnvalue = new string [count];
Returnvalue = autocompletewordlist;
Autocompletewordlist = NULL;
// Return data
Return returnvalue;
}

}

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.