Hi,
I try to Bind an RadAutoCompleteBox with a Dictionnary, but I have this error message when the page is loaded and I tap a letter into the RadAutoCompleteBox => "The control DataSource(or DataSourceID) is not set."
I try the following code :
ASCX :
<telerik:RadAutoCompleteBox runat="server" ID="RadAutoCompleteBox1" InputType="Text" Width="200" DropDownWidth="150px"></telerik:RadAutoCompleteBox>
ASCX.CS
01.protected void Page_Load(object sender, EventArgs e)02.{03. if (!Page.IsPostBack)04. {05. Dictionary<int, string> dict = new Dictionary<int, string>();06. dict.Add(1, "Ann");07. dict.Add(2, "John");08. dict.Add(3, "Mary");09. RadAutoCompleteBox1.DataSource = dict;10. RadAutoCompleteBox1.DataTextField = "Value";11. RadAutoCompleteBox1.DataValueField = "Key";12. }13.}
Thanks for helping me
7 Answers, 1 is accepted
Or maybe it's possible to bind it with a RadMenu ? or a List<RadMenuItem> ?
Thanks for helping me
You should bind the RadAutoCompleteBox control on Page_Load and the DataBind method must be called after setting the DataSource property:
protected void Page_Load(object sender, EventArgs e){ Dictionary<int, string> dict = new Dictionary<int, string>(); dict.Add(1, "Ann"); dict.Add(2, "John"); dict.Add(3, "Mary"); RadAutoCompleteBox1.DataSource = dict; RadAutoCompleteBox1.DataTextField = "Value"; RadAutoCompleteBox1.DataValueField = "Key"; RadAutoCompleteBox1.DataBind();}Attached you may a project I made for testing using the code you sent.
Please check our help articles for more information on DataBindings:
http://docs.telerik.com/devtools/aspnet-ajax/controls/autocompletebox/data-binding/overview
Regards,
Aneliya Petkova
Telerik
Hi,
Thanks, I totally forgot it ^^"
Could you explain me something ? When I do this :
protected void Page_Load(object sender, EventArgs e){ if (!Page.IsPostBack) { //Dictionnary, datasource, databind of RadAutoCompleteBox ... }}protected void Page_Load(object sender, EventArgs e){ if (!Page.IsPostBack) { //... } //Dictionnary, datasource, databind of RadAutoCompleteBox ...}It works ....
Could you explain me that ?
Thanks by the way !
I am glad that I was helpful.
The RadAutoCompleteBox control should be bound on Page_Load, because every time when a user starts typing into the input area, the control is doing a post request to the server and returns the filtered data-source against the typed text.
Regards,
Aneliya Petkova
Telerik
Have a good day!
Hi again !
I finaly use a DropDownItemTemplate
<DropDownItemTemplate> <table cellpadding="0" cellspacing="0"> <tr> <td> <%# DataBinder.Eval(Container.DataItem, "Text")%> <img style="vertical-align:middle" src="icon_pin.png" Title="<%# DataBinder.Eval(Container.DataItem, "Attributes['Chemin']")%>" Alt="?"/> </td> </tr> <tr> <td style="font-style:italic"> <%# DataBinder.Eval(Container.DataItem, "Attributes['IdNiveau']")%> </td> </tr> </table> </DropDownItemTemplate> And I wanna know how get the "DropDownItemTemplate" when user select an item ?
I try with the "AutoCompleteEntryEventArgs" but I have just access to "Text" and "Value", I want access to "Attributes['IdNiveau']"
Regards
In order to keep threads short and concise, I would suggest you to open a separate thread for your last question.
Thank you in advance for your understanding and cooperation.
Regards,
Aneliya Petkova
Telerik