This is a migrated thread and some comments may be shown as answers.

[Solved] Autocomplete client object: I need the ID as well as Value

2 Answers 144 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dennis
Top achievements
Rank 1
Dennis asked on 14 Nov 2010, 11:44 PM

I am using the AutoCompleteBox and when I use the client side onclose event, the value and the text return the same data (the message box will show something like "Combo box closed: { Pablo Picasso } id = Pablo Picasso").

Is there a way to get at the ID returned from my controller object?

Thanks, Dennis

here's my script:

<script type="text/javascript">
    function ComboBox_OnClose(e) {
        var combobox = $(this).data('tAutoComplete');
        var value = combobox.value();
        var text = combobox.text();
        alert("Combo box closed: { " + text + " } id = " + value);
    }
</script>
 The messagebox shows the entry as expected, but I would also like to access the ID that goes along with the name.

My Autocomplete is declared as follows:
<% 
    Html.Telerik().AutoComplete()
        .Name("ArtistNameAutoComplete")
        .DataBinding(dataBinding => dataBinding
            .Ajax().Select("GetArtistNames", "Artist").Delay(300))
        .ClientEvents(events => events.OnClose("ComboBox_OnClose"))
        .Render();
 %>

And my controller method looks like this:
public ActionResult GetArtistNames(string text)
{
    AdminCatalogEntities ctx = new AdminCatalogEntities();
  
    var anames = from a in ctx.Artists
                    where a.Name.StartsWith(text)
                    orderby a.Name
                    select new VMIDName()
                    {
                        ID = a.ID,
                        Name = a.Name
                    };
  
    return new JsonResult { Data = new SelectList(anames.ToList(), "ID", "Name") };
}

2 Answers, 1 is accepted

Sort by
0
Eugenio Alonso
Top achievements
Rank 1
answered on 15 Nov 2010, 07:12 AM
I have the same problem

thanks, Eugenio
0
Katy
Top achievements
Rank 1
answered on 05 Jan 2011, 12:30 AM
Hi 

I have the same problem. Is there any solution?

Please help me
Katy
Tags
ComboBox
Asked by
Dennis
Top achievements
Rank 1
Answers by
Eugenio Alonso
Top achievements
Rank 1
Katy
Top achievements
Rank 1
Share this question
or