Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

baskar
More...


Resources » Code Snippets » AJAX

Using AutocompleteExtender getting multiple data


Posted Date:     Category: AJAX    
Author: Member Level: Silver    Points: 10



 


1) Create a employee table

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[empMaster]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[empMaster]
GO


CREATE TABLE [dbo].[empMaster] (
[empcode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[empname] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO



2) Create Autosuggest web service. Name webservice form as AutoSuggest.asmx

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;

using System.Collections.Generic;

///
/// Summary description for AutoSuggest
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoSuggest : System.Web.Services.WebService
{

[WebMethod]
public string[] GetEmployeeList(string prefixText)
{
strQuery="select empcode,empname from empMaster";
SqlDataReader rdrSql;
rdrSql=SqlHelper.ExecuteReader(strConn,CommandType.Text,strQuery);
while (rdrSql.Read())
{
String vempid=rdrSql.GetString(0);
String vEmpid=rdrSql.GetString(1);
string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem("Emp Name : " + vempname + " - Emp code : " + vEmpid, vEmpid);
names.Add(item);
}
return names.ToArray();

}


}


3) Create new webform.aspx.

a)Add ScriptManager and name as scriptmanager1. Add ServiceReference Path as AutoSuggest.asmx


ScriptManager ID="ScriptManager1" runat="server" >

ServiceReference Path="AutoSuggest.asmx" />




b) Add a label and name as lblEmpCode
Label ID="lblEmpCode" runat="server">
c) Add javaScript tag. Add the function below:

function GetCode(source, eventArgs ){

var textval=eventArgs.get_text();
var temp = new Array();
temp = textval.split('-');

var temp1=new Array();
temp1=temp[0].split(':');

var txtval=temp1[1];
//alert(txtval);
var txtNameEl=document.getElementById("txtEmpName");
var elMyElement = document.getElementById("lblEmpCode");
elMyElement.innerHTML= eventArgs.get_value();
txtNameEl.innerText=txtval.trim();

}

d) Add a TextBox name it txtEmpName. Add AutoCompleteExtender.


TextBox ID="txtEmpName" runat="server" Height="20px" Width="245px" >
      
AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" TargetControlID="txtEmpName" ServiceMethod="GetEmployeeList" ServicePath= "AutoSuggest.asmx" CompletionInterval="1" EnableCaching="true" CompletionSetCount="10" OnClientItemSelected="GetCode">

5) Compile and run

Attachments
  • copy the below code in .aspx page (22235-4327-autocompletecode.txt)





  • Did you like this resource? Share it with your friends and show your love!


    Responses to "Using AutocompleteExtender getting multiple data"

    No responses found. Be the first to respond...

    Feedbacks      

    Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: addrotator with ajax-addrotator autorefresh
    Previous Resource: How to use autocompleteTextbox in Ajax
    Return to Resources
    Post New Resource
    Category: AJAX


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Autocomplete  .  Ajax Autocomplete  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.