AutoCompleteBox without data source

9 posts, 0 answers
  1. Roland Klug
    Roland Klug avatar
    26 posts
    Member since:
    Dec 2002

    Posted 14 Jul 2014 Link to this post

    Hello,

    I'd like to use the RadAutoCompleteBox without specifying a data source or data source id. Instead I want to allow the user to add custom entries. When entering any custom text I get the alert message "The control DataSource(or DataSourceID) is not set.".

    How can I avoid this alert?

    I found a thread about this topic, but it couldn't solve my issue: http://www.telerik.com/forums/autocomplete-with-no-database

    Pleas help! Thank you very much in advance.

    Roland
  2. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 15 Jul 2014 Link to this post

    Hello Roland,

    Would you elaborate on why the suggested approach from the forum wouldn't work in your case?

    Regards,
    Bozhidar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Roland Klug
    Roland Klug avatar
    26 posts
    Member since:
    Dec 2002

    Posted 27 Jul 2014 in reply to Bozhidar Link to this post

    Hello Bozhidar,

    thank you for your reply.Now it works for me, too. I didn't set the empty datasource on every postback, only on the first page load.

    Regards,
    Roland.
  5. LGFox
    LGFox avatar
    3 posts
    Member since:
    Aug 2014

    Posted 13 Aug 2014 Link to this post

    Good day!

    I've created two same projects with different "Telerik.Web.UI.dll" version (2013.3.1114.40 and 2014.2.618.40).
    New version of the library don't support an empty datasource of RadAutoCompleteBox when it used inside an EditForm of RadGrid control. It's falling with "DataSource not set" exception when I press "Edit" linkbutton.

    But when I've used it at Sitefinity - no exception displayed. Grid just doesn't go in EditMode.
    Default.aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <telerik:RadScriptManager runat="server" />
                <telerik:RadGrid PageSize="5" OnItemDataBound="ThatGrid_OnItemDataBound" OnNeedDataSource="ThatGrid_OnNeedDataSource" AllowPaging="True" ID="ThatGrid" runat="server">
                    <MasterTableView EditMode="EditForms" DataKeyNames="key">
                        <EditFormSettings EditFormType="Template">
                            <FormTemplate>
                                <asp:Label runat="server" ID="LabelValue" Text="<%# Bind('value') %>"></asp:Label>
                                <telerik:RadAutoCompleteBox runat="server" ID="RadAutoCompleteBoxValue" InputType="Token"
                                    Width="300px" Delimiter=";" AllowCustomEntry="True" EmptyMessage="Type here...">
                                </telerik:RadAutoCompleteBox>
                            </FormTemplate>
                        </EditFormSettings>
                        <Columns>
                            <telerik:GridEditCommandColumn HeaderStyle-Width="40px" ButtonType="LinkButton">
                            </telerik:GridEditCommandColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
            </div>
        </form>
    </body>
    </html>

    Default.aspx.cs:
    using System;
    using System.Collections.Generic;
    using Telerik.Web.UI;

    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private Random Rand = new Random();

        protected void ThatGrid_OnNeedDataSource(object sender, EventArgs e)
        {
            int count = 20;
            var ds = new Dictionary<int, string>();
            for (var i = 0; i < count; i++)
            {
                ds.Add(i, "Test " + i.ToString());
            }
            ThatGrid.DataSource = ds;
        }
        protected void ThatGrid_OnItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
            {

            }

            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                //var setting = (Dictionary<int, string>)e.Item.DataItem;
                var item = e.Item as GridEditFormItem;
            }
        }
    }
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Aug 2014 in reply to LGFox Link to this post

    Hi,

    The DataSource of the RadAutoCompleteBox should be supplied regardless if a PostBack occurs or not. The binding mechanism of the control, relies on the currently type character ( where a callback occurs ) upon which the control is populated. Each time a character is typed, a callback is initiated in order to performed the query to the used datasource.  Please try to attach the DataSource to RadAutoCompleteBox in proper event.

    Thanks,
    Princy. 
  7. LGFox
    LGFox avatar
    3 posts
    Member since:
    Aug 2014

    Posted 14 Aug 2014 in reply to Princy Link to this post

    Thanks for answer, Princy!
    But I try to assign a datasource (list<> from a model of MS Entity framework) at "OnItemDataBound" handler:
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) { /* Assign a datasource here */ }

    But the code in the "IF" statement never be executing, because of an exception "Datasource not set" when I press "Edit" command button. It seems, datasource has requested early before "OnItemDataBound" event. And there is no "OnNeedDataSource" event.

    So I cann't found appropriate event or DataSource construction (compatible with MS Entity frm.).

    Any help appreciated! Thanks!
  8. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 15 Aug 2014 Link to this post

    Hello,

    Could you please open a support ticket and send us a runnable sample project, which demonstrates the issue to examine it locally?

    Regards,
    Helen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Aug 2014 in reply to LGFox Link to this post

    Hi,

    Try to attach the OnItemCreated event of RadGrid and bind the RadAutoCompleteBox in there as follows.

    C#:
    protected void ThatGrid_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            var item = e.Item as GridEditFormItem;
            RadAutoCompleteBox autocompletebox = (RadAutoCompleteBox)item.FindControl("RadAutoCompleteBoxValue");
            autocompletebox.DataSourceID = "SqlDataSource1";
            autocompletebox.DataBind();
        }
    }

    Thanks,
    Princy.
  10. LGFox
    LGFox avatar
    3 posts
    Member since:
    Aug 2014

    Posted 18 Aug 2014 in reply to Princy Link to this post

    Wow! That works. Thank you, Princy.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017