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

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

1 Answer 132 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
glen wu
Top achievements
Rank 1
glen wu asked on 26 Dec 2012, 08:08 AM
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. 
plus,   
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");
               }
               table.Controls.Add(titleRow);
               table.Controls.Add(dataRow);
               container.Controls.Add(table);
           }
       }
       private void AddBindItem(Control container, HtmlTableRow titleRow, String strTitle, HtmlTableRow dataRow, String strContactName)
       {
           HtmlTableCell cellTitle = new HtmlTableCell();
           cellTitle.InnerHtml = strTitle;
           titleRow.Cells.Add(cellTitle);
 
           HtmlTableCell cellData = new HtmlTableCell();
           Label lab = new Label();
           lab.Text = (string)DataBinder.Eval((container as Telerik.Web.UI.AutoCompleteBox.DropDownItem).DataItem, strContactName);
           cellData.Controls.Add(lab);
           dataRow.Controls.Add(cellData);
 
       }
 
       public void RadAutoCompleteBox_DropDownTemplateNeeded(object sender, AutoCompleteDropDownItemEventArgs e)
       {
           e.Item.Template = new ReceivingSheetDropDownItemTemplate();
       }

page logic:
protected void Page_Load(object sender, EventArgs e)
        {
            BindAutoCompleteBox();
        }
 
        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>

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 28 Dec 2012, 04:03 PM
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,
Bozhidar
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.
Tags
AutoCompleteBox
Asked by
glen wu
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or