We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Autocomplete bind text and code


How to bind code and text value in Auto complete text box   and get code behind text and code 

            List<Countries> c = new List<Countries>();

            c.Add(new Countries { text = "Austria", ID = "100001" });

            c.Add(new Countries { text = "Australia", ID = "20002" });

            c.Add(new Countries { text = "Bangladesh", ID = "300003" });


            this.categoryGrouping.DataSource = c;

            categoryGrouping.DataTextField = "text";

            categoryGrouping.DataUniqueKeyField = "ID";




        class Countries


            public string text;

            public string ID;


       protected void Button1_Click(object sender, EventArgs e)


            string txt = categoryGrouping.DataTextField.ToString();

            string code = categoryGrouping.DataUniqueKeyField.ToString();




Attachment: Autocomplete_7fdc507c.rar

5 Replies

NP Narayanasamy Panneer Selvam Syncfusion Team August 17, 2016 10:58 AM UTC

Hi Pratheep,   
Thanks for Contacting Syncfusion Support.   
We have analyzed the attached project file and we suspect that this issue may occurs due to “ej.webforms.min.js” Script file which you may missed to refer in your sample. You can get the text and key value of the selected Autocomplete item, using the Value and SelectValueByKey properties in code behind. We have prepared a sample with your requirement, find it in the below link.  
For further references check the below,   
If this is not your requirement kindly revert with your exact scenario. So that we can help you out best.    
Narayanasamy P

PR Pratheep August 23, 2016 12:59 PM UTC

Hi Narayanasamy 

Thank you for your sample project.run that project  Autocomplete Items not populate ( not binding any data  ) 



NP Narayanasamy Panneer Selvam Syncfusion Team August 24, 2016 09:01 AM UTC

Hi Pratheep, 
Thanks for Your update.

We were Unable to reproduce your issue with autocomplete sample which we have shared. We have attached a video sample for your reference. Please find the video sample in the following link: http://www.syncfusion.com/downloads/support/directtrac/general/AUTOCO~2-2010637154.ZIP 
Still if you are facing any issue please let us know with screenshots of your browser’s console window during the sample is running. So that we can help you out better. 

Narayanasamy P. 

PR Pratheep August 24, 2016 12:48 PM UTC

Hi Narayanasamy

Thank you for your replay. still I have facing that issue,here i have attached screenshots.I don't know where is wrong


Attachment: auto_6545015d.rar

NP Narayanasamy Panneer Selvam Syncfusion Team August 25, 2016 12:09 PM UTC

Hi Pratheep,   
Thanks for your update.   
  We were unable to reproduce the issue in the shared screenshots. If you are facing an issue after PostBack function call, we suggest that you use  DataSourceCachingMode="ViewState" in our control.    
Example code:   
<ej:Autocomplete ID="categoryGrouping" Width="205px"  ShowPopupButton="true" FilterType="Contains" HighlightSearch="true" DataSourceCachingMode="ViewState"  runat="server" WatermarkText="Select a category" ClientSideOnSelect="OnSelect"/> 
After this, if you still face any errors, then please share the following details.  
      Run the sample and open the developer tools in your browser using F12 key. Share the error message, if there is any error in console or else check whether the referred script and CSS are loaded properly.   
     In the Visual studio application, expand the reference field and if you find any of the reference         missing, please refer to the missed dll from your machine.  
    Ensure whether the script and CSS are available in your application.  
Narayanasamy P. 

Live Chat Icon For mobile
Up arrow icon