Saturday, April 7

Auto Complete Textbox To Store Id While Displaying Name

This is my overall view of the application

Now the below Diagram shows the overall View of My Database:-

Now the below Diagram shows the Design View of My web Page Default.aspx:-

Now the below Diagram shows the Source View of My web Page Default.aspx:-

You can Copy the Source code of My web Page Default.aspx here :-

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" language="javascript">
        function GetCode(source, eventArgs) {
            document.getElementById("hCode").value = eventArgs.get_value();
            document.getElementById("hdnCompanyName").value = source;
        function hCode_onclick() {

    <style type="text/css">
            width: 100%;
            width: 133px;
            color: #336600;
            color: #800000;
            width: 133px;
            color: #000099;
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services><asp:ServiceReference Path="CompanyServiceForAutoSuggest.asmx" /> </Services></asp:ScriptManager>
    <div> <h1><span class="style4">Om Namah Shivaya(</span><span class="style3">Auto Complete Textbox To Store Id While Displaying Name</span><span class="style4">)</span></h1>
        <table class="style1"><tr> <td class="style5"><strong>Shibashish Name:</strong></td><td><asp:TextBox ID="txtManufacturer" runat="server"/>
    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtManufacturer" ServicePath="CompanyServiceForAutoSuggest.asmx"
   ServiceMethod="GetCountries" CompletionInterval="100"  CompletionSetCount="20"  MinimumPrefixLength="1" OnClientItemSelected="GetCode" /></td> </tr>  <tr> <td class="style2">
     &nbsp;</td><td> &nbsp;</td></tr> <tr> <td class="style2">  &nbsp;</td><td> &nbsp;</td>  </tr><tr> <td class="style5"> <strong>Hidden stored ID:</strong></td>
    <td><input type="text" id="hCode" runat="server" value="0" /></td> </tr>  <tr> <td class="style2"> &nbsp;</td> <td> &nbsp;</td></tr></table> </div>

Now the below Diagram shows the code of  Web.cofig:-

You can Copy the  code of  Web.cofig  here and change it according to your connectionstring :-

<?xml version="1.0"?>
 <add name="TestConnectionString" connectionString="Data Source=SWASH-DBS\SWASHSQLINT;Initial Catalog=Test;Persist Security Info=True;User ID=ken;Password=kc@2011"
    <compilation debug="true" targetFramework="4.0"/>

Here is the web Service Code That I have used in My application

<%@ WebService Language="C#" Class="CompanyServiceForAutoSuggest" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
public class CompanyServiceForAutoSuggest  : System.Web.Services.WebService {
    public string HelloWorld() {
        return "Hello World";
    public List<string> GetCountries(string prefixText)
        string constring = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(constring);
        if (con.State != ConnectionState.Open)
        SqlCommand cmd = new SqlCommand("select * from TextboxAutoImpliment where Name like @Name", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        List<string> Name = new List<string>();
        if (dt.Rows.Count > 0){
            for (int i = 0; i < dt.Rows.Count; i++)
                Name.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i][1].ToString(), Convert.ToString(dt.Rows[i][0].ToString())));
        return Name;


After running the application:-

      Shibashish Mohanty

No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

shibashish mohanty