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

Error with AutoCompleteBox inside asp:Repeater

1 Answer 85 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 28 Jan 2018, 11:33 PM

Hello,

 

I have a page that I'm building that uses a AutoCompleteBox inside of a repeater.  I am trying to load the control inside of the the ItemDataBound method of the repeater, but an error gets thrown before it can even be called saying "Datasource not set" referring to the AutoCompleteBox.  Is there a specific way that I should be loading the control?  Here is a snippet of the control being loaded inside the ItemDataBound method of the repeater.  Thanks for any help.

 

{

     RepeaterItem item = e.item;

 

    txtAgent = (RadAutoCompleteBox)item.FindControl("txtAgent");

    txtAgent.DataSource  = Agent.GetListOfAgents();

    txtAgent.DataBind();

}

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 31 Jan 2018, 03:10 PM
Hello Daniel,

TData bound controls call the .DataBind() method of their items between the ItemCreated and ItemDataBound event. This causes the autocomplete box to data bind. Since it has no data source set yet, it throws an exception.

More information can be found in the DataSource not set error thrown when data source is provided in ItemDataBound KB article.

<asp:Repeater ID="Repeater1" runat="server"
    DataSourceID="SqlDataSource1" OnItemCreated="Repeater1_ItemCreated" >
    <ItemTemplate>
        <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" runat="server"></telerik:RadAutoCompleteBox>
        <br />
    </ItemTemplate>
</asp:Repeater>
 
<asp:SqlDataSource
    ConnectionString=
        "<%$ ConnectionStrings:NorthwindConnectionString %>"
    ID="SqlDataSource1" runat="server"
    SelectCommand="SELECT [CategoryID], [CategoryName],
        [Description] FROM [Categories]">
</asp:SqlDataSource>
protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
{
    RepeaterItem item = e.Item;
 
    string[] ds = Page.IsCallback ? new string[] { "aaa", "bbb", "ccc", "ddd", "sss" } : new string[] { "" };
 
    var txtAgent = (RadAutoCompleteBox)item.FindControl("RadAutoCompleteBox1");
    txtAgent.DataSource = ds;
}

Let us know how that works for you or if you have any feedback or improvement suggestions regarding the KB article.

Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
AutoCompleteBox
Asked by
Daniel
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or