DataSource Issue within RadGrid

2 posts, 0 answers
  1. Rengo
    Rengo avatar
    25 posts
    Member since:
    Nov 2012

    Posted 02 Apr 2013 Link to this post

    Hello,

    I have a RadAutoCompleteBox control within a RadGrid.  I am able to bind the control during the page load.  Although, when I start typing in the RadAutoCompletebox, I receive the following message.



    Grid HTML:
     <telerik:GridTemplateColumn HeaderText="Media Title" UniqueName="MediaTitle" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="330px"  ItemStyle-Wrap="false">
                    <ItemTemplate>
                       <telerik:RadAutoCompleteBox ID="cboMaster" InputType="Text" runat="server" Filter="Contains" Width="300px" DropDownWidth="250px">
                        </telerik:RadAutoCompleteBox>
                      </ItemTemplate>
                    </telerik:GridTemplateColumn>

    RadAutoCompleteBox Binding (Page_Load):
     cboMaster.DataValueField = "ID";
     cboMaster.DataTextField = "Title";
     cboMaster.DataSource = GetMediaSourceTitles();
     cboMaster.DataBind();

    What am I missing so users can type in the RadAutoCompleteBox and display the matching entries?

    Thank You in Advance!
  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 05 Apr 2013 Link to this post

    Hello Robert,

    I would suggest you to use the OnItemDataBound event, instead of the Page_Load, since the RadGrid is not completely initiated at that stage of the life cycle. Please consider the following implementation:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                RadAutoCompleteBox cboMaster = dataItem["MediaTitle"].Controls[1] as RadAutoCompleteBox;
                cboMaster.DataValueField = "ID";
                cboMaster.DataTextField = "Title";
                cboMaster.DataSource = GetMediaSourceTitles();
                cboMaster.DataBind();
            }
        }




    Greetings,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top