The control DataSource(or DataSourceID) is not set.

8 posts, 1 answers
  1. Jérémy
    Jérémy avatar
    19 posts
    Member since:
    Feb 2015

    Posted 15 Jul 2015 Link to this post

    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

  2. Jérémy
    Jérémy avatar
    19 posts
    Member since:
    Feb 2015

    Posted 16 Jul 2015 in reply to Jérémy Link to this post

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

    Thanks for helping me

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 17 Jul 2015 Link to this post

    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
  5. Jérémy
    Jérémy avatar
    19 posts
    Member since:
    Feb 2015

    Posted 17 Jul 2015 in reply to Aneliya Petkova Link to this post

    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 !

  6. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 20 Jul 2015 Link to this post

    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
  7. Jérémy
    Jérémy avatar
    19 posts
    Member since:
    Feb 2015

    Posted 20 Jul 2015 Link to this post

    Thank for your help and this explaination.
    Have a good day!
  8. Jérémy
    Jérémy avatar
    19 posts
    Member since:
    Feb 2015

    Posted 20 Jul 2015 Link to this post

    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

  9. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 20 Jul 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017