Relatively simple simulation, text box input CompanyName, and then
Search the CompanyName field in the SqlServer2000 Northwind database Suppliers table,
And then the implementation is done automatically
Four files
1. Autocomplete.htm
[Run code] [Copy to Clipboard] [ ± ] CODE:
Input Auto Completion
Companyname
of the dropdown table
Autocomplete.aspx
<%@ Page language= "C #" autoeventwireup= true "codebehind=" AutoComplete.aspx.cs "inherits=" Ajaxbasehome.autocomplete "%>
AutoComplete.aspx.cs
[Run code] [Copy to Clipboard] [ ± ] CODE:
Using System;
Using System.Data;
Using System.Data.SqlClient;
Using System.Configuration;
Using System.Collections;
Using System.IO;
Using System.Text;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Web.Configuration;
Namespace Ajaxbasehome
{
public partial class AutoComplete:System.Web.UI.Page
{
private static string constring = webconfigurationmanager.connectionstrings["MyData"]. ConnectionString;
protected void Page_Load (object sender, EventArgs e)
{
string input = GetInput ();
Response.Write (Input) (getcompanyname);
}
Gets the input string
private String GetInput ()
{
Stream s = request.inputstream;
int count = 0;
byte[] buffer = new byte[1024];
StringBuilder builder = new StringBuilder ();
while ((count = s.read (buffer, 0, 1024)) > 0)
{
Builder. Append (Encoding.UTF8.GetString (buffer, 0, count));
}
Return builder. ToString ();
}
private string Getcompanyname (String input)
{
using (SqlConnection con = new SqlConnection (constring))
{
SqlCommand command = new SqlCommand ("select * from suppliers where CompanyName like @Name", con);
Command. Parameters.Add (New SqlParameter ("@name", input + "%"));
SqlDataAdapter adapter = new SqlDataAdapter (command);
DataSet ds = new DataSet ();
Adapter. Fill (DS);
Return DS. GETXML ();
}
}
}
}
XSLT file for displaying XML data
[Run code] [Copy to Clipboard] [ ± ] CODE:
<TD style= "Cursor:hand" >