How to get the value in a whole field of an AutoCompleteBox?

2 posts, 0 answers
  1. glen wu
    glen wu avatar
    1 posts
    Member since:
    May 2010

    Posted 26 Dec 2012 Link to this post

    I'd like to realize a  AutoCompleteBox , the question is how to get the other values of the text in a whole  line when it has been selected . The templates is re-designed. 
    I can get DataValueField by sender.get_value(), and how to get the value in a whole field.
    Codes Template:
    public class ReceivingSheetDropDownItemTemplate : ITemplate
           Boolean IsCompany { get; set; }
           Boolean IsName{get;set;}
           Boolean IsPhone{get;set;}
           Boolean IsMobile{get;set;}
           Boolean IsAddress{get;set;}
           public ReceivingSheetDropDownItemTemplate(Boolean isCompany = true, Boolean isName = true, Boolean isPhone = true, Boolean isMobile = true, Boolean isAddress = true)
               IsCompany =isCompany;
               IsName =isName;
               IsPhone = isPhone;
               IsMobile = isMobile;
               IsAddress = isAddress;
           public void InstantiateIn(Control container)
               if (IsCompany || IsName || IsPhone || IsMobile || IsAddress)
                   HtmlTable table = new HtmlTable();
                   HtmlTableRow titleRow = new HtmlTableRow();
                   HtmlTableRow dataRow = new HtmlTableRow();
                   titleRow.Attributes.Add("class", "title");
                   table.Attributes.Add("class", "DropTable");
                   if (IsCompany)
                       AddBindItem(container, titleRow, "CompanyName", dataRow, "CompanyName");
                   if (IsName)
                       AddBindItem(container, titleRow, "Name", dataRow, "Name");
                   if (IsPhone)
                       AddBindItem(container, titleRow, "Phone", dataRow, "Phone");
                   if (IsMobile)
                       AddBindItem(container, titleRow, "Mobile", dataRow, "Mobile");
                   if (IsAddress)
                       AddBindItem(container, titleRow, "Address", dataRow, "Address");
           private void AddBindItem(Control container, HtmlTableRow titleRow, String strTitle, HtmlTableRow dataRow, String strContactName)
               HtmlTableCell cellTitle = new HtmlTableCell();
               cellTitle.InnerHtml = strTitle;
               HtmlTableCell cellData = new HtmlTableCell();
               Label lab = new Label();
               lab.Text = (string)DataBinder.Eval((container as Telerik.Web.UI.AutoCompleteBox.DropDownItem).DataItem, strContactName);
           public void RadAutoCompleteBox_DropDownTemplateNeeded(object sender, AutoCompleteDropDownItemEventArgs e)
               e.Item.Template = new ReceivingSheetDropDownItemTemplate();

    page logic:
    protected void Page_Load(object sender, EventArgs e)
            private void BindAutoCompleteBox()
                rAutoReceiveCompany.DropDownTemplateNeeded += new  ReceivingSheetDropDownItemTemplate().RadAutoCompleteBox_DropDownTemplateNeeded;
                rAutoReceiveCompany.DataSource = new BLL.BaseInfo.ReceiveCompany().GetIsReceiveCompany(true);
                rAutoReceiveCompany.DataTextField = "CompanyName";
                rAutoReceiveCompany.DataValueField = "CompanyName";

     UI :
    <tk:RadAutoCompleteBox ID="rAutoDeliverCompany" runat="server" Filter="StartsWith" TextSettings-SelectionMode="Single" AllowCustomEntry="true" InputType="Text"></tk:RadAutoCompleteBox>
  2. Bozhidar
    Bozhidar avatar
    1146 posts

    Posted 28 Dec 2012 Link to this post

    Hi Glen,

    These properties are not available on the client directly. In order to get them you can use the dropdownitem's DOM element and manually collect them from the table cell's values. Here's some sample code to guide you in the right direction:
    $(".racSlide").on("click", ".racItem", function(e) {
        var table = $(e.currentTarget).find("table").get(0);
        var firstCellText = $(table.rows[0].cells[0]).text();
        var secondCellText = $(table.rows[0].cells[2]).text();

    Kind regards,
    the Telerik team
    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 their blog feed now.
Back to Top