New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

OnDropDownTemplateNeeded

The DropDownTemplateNeeded event occurs before template is being applied to the drop-down item. It is commonly used for dynamic templating.

The DropDownTemplateNeeded event handler receives two arguments:

  1. The RadAutoCompleteBox object. This argument is of type object, but can be cast to the RadAutoCompleteBox type.

  2. An AutoCompleteDropDownItemEventArgs object. This object has an Item property of type DropDownDataItem.

Use the DropDownTemplateNeeded event handler create templates dynamically.

ASPNET
<telerik:RadAutocompleteBox runat="server" id="RadAutoCompleteBox1" inputtype="Token"
	datasourceid="SqlDataSource1" width="400px" datatextfield="ContactName" dropdownwidth="400px"
	ondropdowntemplateneeded="RadAutoCompleteBox1_DropDownTemplateNeeded">
	</telerik:RadAutocompleteBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
	ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP 6 * FROM [CustomerPhotos]" />
C#
	
public partial class AutoComplete_Examples_Templates_DefaultCS : System.Web.UI.Page
{

	protected void RadAutoCompleteBox1_DropDownTemplateNeeded(object sender, AutoCompleteDropDownItemEventArgs e)
	{
		e.Item.Template = new CustomContentTemplate();
	}
}

class CustomContentTemplate : ITemplate
{
	public void InstantiateIn(Control container)
	{
		Label label1 = new Label();
		label1.Font.Bold = true;
		label1.DataBinding += new EventHandler(label1_DataBinding);
		container.Controls.Add(label1);
	}

	private void label1_DataBinding(object sender, EventArgs e)
	{
		Label target = (Label)sender;
		DropDownDataItem item = (DropDownDataItem)target.BindingContainer;
		string itemText = (string)DataBinder.Eval(item.DataItem, "ContactName");
		target.Text = itemText;
	}
}
	

See Also

In this article
See Also
Not finding the help you need?
Contact Support