Issue binding RadAutoCompleteBox in edit template form

3 posts, 1 answers
  1. Teodora
    Teodora avatar
    2 posts
    Member since:
    Jan 2017

    Posted 20 Jan Link to this post

    Hello!

    I am having a RadAutoCompleteBox in the edit template form of my RadGrid. I am trying to bind it to a string array in my code behind file. The control is rendered but when I try to type in it I get DataSource(or DataSourceID) is not set error. Here are some code snippets:

    ASCX

    <EditFormSettings EditFormType="Template">
       <FormTemplate>
          <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" runat="server" DataSource="<%#AutoCompleteBoxDataSource%>" InputType="Token" AllowCustomEntry="true"></telerik:RadAutoCompleteBox>
        </FormTemplate>
    </EditFormSettings>

     

    ASCX.CS

    public string[] AutoCompleteBoxDataSource;
     
    protected void Page_Load(object sender, EventArgs e)
    {
      AutoCompleteBoxDataSource = new string[] { "value1", "value2", "value3", "value4" };
    }
        
    protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {           
       if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
        {
           GridEditFormItem editform = (GridEditFormItem)e.Item;
           RadAutoCompleteBox racEditForm= (RadAutoCompleteBox)editform.FindControl("RadAutoCompleteBox1");
           if (racEditForm= != null)
            {
              racEditForm.DataSource = AutoCompleteBoxDataSource;
              racEditForm.DataBind();
            }
         }
    }

     

    I've tried removing the DataSource from the .ascx file but it caused a server error saying DataSource not set. I have another RadAutoCompleteBox control outside of the RadGrid which is working without any issues.

    Thanks in advance!

    Regards,

    T.Toncheva

  2. Answer
    Nencho
    Admin
    Nencho avatar
    1519 posts

    Posted 25 Jan Link to this post

    Hello Teodora,

    I would suggest you to use the OnLoad event of the RadAutoCompleteBox , in order to bind it to the preferable datasource:

    <telerik:RadAutoCompleteBox runat="server" ID="RadAutoCompleteBox1" OnLoad="RadAutoCompleteBox1_Load"></telerik:RadAutoCompleteBox>
     
    ........
     
        protected void RadAutoCompleteBox1_Load(object sender, EventArgs e)
        {
            RadAutoCompleteBox auto = (sender as RadAutoCompleteBox);
            auto.DataSource = new string[] { "item 1", "item 2" };
        }


    Regards,
    Nencho
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Teodora
    Teodora avatar
    2 posts
    Member since:
    Jan 2017

    Posted 26 Jan in reply to Nencho Link to this post

    Hello Nencho,

    Thank you for your answer! This resolved my issue.

    Regards,

    Teodora

Back to Top