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

The control DataSource(or DataSourceID) is not set.

7 Answers 914 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Jérémy
Top achievements
Rank 1
Jérémy asked on 15 Jul 2015, 08:42 AM

Hi,

 I try to Bind an RadAutoCompleteBox with a Dictionnary, but I have this error message when the page i​s 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

Sort by
0
Jérémy
Top achievements
Rank 1
answered on 16 Jul 2015, 02:04 PM

Or maybe it's possible to bind it with a RadMenu ? or a List<RadMenuItem> ?

Thanks for helping me

0
Accepted
Aneliya Petkova
Telerik team
answered on 17 Jul 2015, 09:53 AM
Hi vallin,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jérémy
Top achievements
Rank 1
answered on 17 Jul 2015, 12:06 PM

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 ...
  }
}
I have the error message, but when I do this :

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 !

0
Aneliya Petkova
Telerik team
answered on 20 Jul 2015, 06:34 AM
Hi vallin,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jérémy
Top achievements
Rank 1
answered on 20 Jul 2015, 07:05 AM
Thank for your help and this explaination.
Have a good day!
0
Jérémy
Top achievements
Rank 1
answered on 20 Jul 2015, 12:37 PM

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

0
Aneliya Petkova
Telerik team
answered on 20 Jul 2015, 01:33 PM
Hi vallin,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
AutoCompleteBox
Asked by
Jérémy
Top achievements
Rank 1
Answers by
Jérémy
Top achievements
Rank 1
Aneliya Petkova
Telerik team
Share this question
or