Display formatted AutoComplete List in ASP.Net AJAX AutoCompleteExtender

nauna
 
on Jul 19, 2022 11:29 PM
660 Views

The webmethod returns name and type value, i want the output to be formatted in autocomplete extender like

Name should be on left corner and TYPE should be on right corner like

Shayak       Student

Nayak         Teacher

Sudha          Manager

<asp:TextBox ID="txtsearch" placeholder="What service do you need"   ValidationGroup="search" AutoCompleteType="Disabled" runat="server" CssClass="form-control no-border"  ></asp:TextBox>
 <cc1:AutoCompleteExtender ID="AutoCompleteEx"  runat="server" EnableCaching="false"
    BehaviorID="AutoCompleteEx" MinimumPrefixLength="1" TargetControlID="txtsearch"
    ServicePath="~/MyService.asmx" ServiceMethod="Search_services_v2" CompletionInterval="1000"
    CompletionSetCount="20"    
    FirstRowSelected = "true">
</cc1:AutoCompleteExtender>

 

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]      
public List<string> Search_services_v2(string prefixText, int count)
{           
    Entities db = new Entities();
    List<string> customers = new List<string>();
 
    var q = (from vs in db.f_vendorservice_autoserach(prefixText)
             orderby vs.name
             select new
             { 
                 name= vs.name,
                 type=vs.Type
             });
      
    foreach (var item in q)
    {              
        string html = string.Format("{0} {1}", item.name,  item.type);
        customers.Add(html);
    }
 
    return customers;
}

 

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 20, 2022 12:08 AM

Hi nauna,

Use OnClientPopulated property. Refer below article.

Render images in autocomplete list of ASP.Net AJAX AutoCompleteExtender