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

Get return value ID of Autocomplete Box

1 Answer 279 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 22 Jan 2014, 06:06 PM
I have a web service that I want to return 2 values   and ID and a text value hrough and autocompletebox.  I have it working to return the service but now I need to get at the ID value that was returned, not the text value.  I would like to be able to do an Autopostback on the autocompletebox and hit a database with the ID to return more data to the page.  Is this possible iwht the autocompletebox as I have not been able to find code that shows this.  It would be similar to the asp Autocomplete extender that can return 2 values that you can then use.  Can I do this with a telerik AutocompleteBox.


<telerik:radautocompletebox ID="rdSearch" runat="server" EmptyMessage="Type Last Name First Name" EnableAutoComplete="true" MinFilterLength="2" MaxResultCount="20" Width="260px"
                                   DropDownHeight="100px" DropDownWidth="250px" DropDownPosition="static" AutoPostBack="true" OnClientEntryAdded="requesting">
                                    <TextSettings SelectionMode="Single" />
                                    <WebServiceSettings Path="../AutoComplete.asmx" Method="GetNames" />
                                </telerik:radautocompletebox>
 
 
  function requesting(sender, eventArgs) {
            var context = eventArgs.get_context();
            //Data passed to the service.
           // context["ClientData"] = "ClientData_Passed_To_The_Service";
        }
 
 
 [WebMethod]
    public AutoCompleteBoxData GetNames(RadAutoCompleteContext context)
    {
        string sql = "select intPersonnelId, strFullname FullName FROM tblMNNatPersonnel WHERE strFullname like '" + context.Text + "%'";
        //SqlDataAdapter adapter = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
         
        DataTable myDataTable = new DataTable();
        myDataTable = c.GetReader(sql);
 
        List<AutoCompleteBoxItemData> result = new List<AutoCompleteBoxItemData>();
        AutoCompleteBoxData dropDownData = new AutoCompleteBoxData();
 
        result = new List<AutoCompleteBoxItemData>();
 
        for (int i = 0; i < myDataTable.Rows.Count; i++)
        {
            AutoCompleteBoxItemData itemData = new AutoCompleteBoxItemData();
            itemData.Text = myDataTable.Rows[i]["FullName"].ToString();
            itemData.Value = myDataTable.Rows[i]["intPersonnelId"].ToString();
 
            result.Add(itemData);
        }
 
        dropDownData.Items = result.ToArray();
        return dropDownData;
    }
 
When it returns to the autocomplete box I need to do take the intPersonnelId and hit a database and return more information.


1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 27 Jan 2014, 09:28 AM
Hi Kevin,

Please take a look at the following help article related to the Binding of the RadAsutoCompleteBox to Web service. Is this the desired functionality that you need to achieve? As a side note I would like to ask you if you tried using the OData Binding that is already described here? Is this helpful in your scenario?

Regards,
Kate
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
AutoCompleteBox
Asked by
Kevin
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or