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

Issue binding RadAutoCompleteBox in edit template form

2 Answers 87 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Teodora
Top achievements
Rank 1
Teodora asked on 20 Jan 2017, 01:36 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Nencho
Telerik team
answered on 25 Jan 2017, 10:17 AM
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.
0
Teodora
Top achievements
Rank 1
answered on 26 Jan 2017, 08:27 AM

Hello Nencho,

Thank you for your answer! This resolved my issue.

Regards,

Teodora

Tags
AutoCompleteBox
Asked by
Teodora
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Teodora
Top achievements
Rank 1
Share this question
or