← Tutti gli articoli

Ajax Control Toolkit AutoCompleteExtender with Key/Value pair

21 September 2010  ·  Ajax · Article  ·  185 visite

How do I associate a Key-Value pair with textBox autoComplete extender in a way similar to a dropdownlist? It is preferred that value will not be visible to user.

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AnagraficaContrattista.aspx.cs" Inherits="AnagraficaContrattista" %>

<%@ Register

    Assembly="AjaxControlToolkit"

    Namespace="AjaxControlToolkit"

    TagPrefix="ajaxToolkit" %>

    



    

     

  

    
Matricola:
Cognome:
Nome:
CF:


 

 
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Configuration;

using System.Web.Script.Serialization;

using System.Web.Script.Services;

 

using System.Text.RegularExpressions;

using AjaxControlToolkit;

 

using ContraModel;

 

/// 

/// Summary description for Autocomplete

/// 

 

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[ScriptService()]

public class Autocomplete : System.Web.Services.WebService {

 

    public Autocomplete () {

 

        //Uncomment the following line if using designed components 

        //InitializeComponent(); 

    }

 

    [WebMethod]

    [ScriptMethod()]

    public string[] GetContrattisti(string prefixText, int count, string contextKey)

    {

        List items = new List();

        JavaScriptSerializer serializer = new JavaScriptSerializer();

        ContraEntities contraContext = new ContraEntities(ConfigurationManager.ConnectionStrings["ContraCSEntities"].ToString());

        //int numerorecord = 10;

        var listaAnagrafiche = contraContext.sp_AnagraficaAutocomplete(prefixText, count);

 

        // string json=null;

 

        if (listaAnagrafiche != null)

        {

 

 

            JavaScriptSerializer jss = new JavaScriptSerializer();

            foreach (v_Anagrafica v in listaAnagrafiche)

            {

                items.Add(AutoCompleteExtender.CreateAutoCompleteItem(v.Ana_Cognome + " " + v.Ana_Nome, serializer.Serialize(v)));

            }

 

 

 

 

        }

 

        //return json;

 

        return items.ToArray();

 

 

 

 

 

    }

 

    [WebMethod]

    [ScriptMethod()]

    public string[] GetContrattisti2(string prefixText, int count)

    {

        if (count == 0)

        {

            count = 10;

        }

 

 

        if (prefixText.Equals("xyz"))

        {

            return new string[0];

        }

 

 

        Random random = new Random();

        List items = new List(count);

        for (int i = 0; i < count; i++)

        {

            char c1 = (char)random.Next(65, 90);

            char c2 = (char)random.Next(97, 122);

            char c3 = (char)random.Next(97, 122);

 

 

            items.Add(prefixText + c1 + c2 + c3);

        }

 

 

        return items.ToArray(); 

 

 

 

 

 

 

 

    }    

 

       

 

    [WebMethod]

    public string HelloWorld() {

        return "Hello World";

    }

    

}

 

 

Si è verificato un errore imprevisto. Ricarica

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.