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

AutoCompleteBox without data source

8 Answers 355 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Roland Klug
Top achievements
Rank 1
Roland Klug asked on 14 Jul 2014, 07:45 PM
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

8 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 15 Jul 2014, 05:51 AM
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.

 
0
Roland Klug
Top achievements
Rank 1
answered on 27 Jul 2014, 08:55 AM
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.
0
LGFox
Top achievements
Rank 1
answered on 14 Aug 2014, 02:48 AM
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;
        }
    }
}
0
Princy
Top achievements
Rank 2
answered on 14 Aug 2014, 10:04 AM
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. 
0
LGFox
Top achievements
Rank 1
answered on 14 Aug 2014, 10:39 AM
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!
0
Helen
Telerik team
answered on 15 Aug 2014, 12:47 PM
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.

 
0
Princy
Top achievements
Rank 2
answered on 18 Aug 2014, 05:03 AM
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.
0
LGFox
Top achievements
Rank 1
answered on 18 Aug 2014, 10:49 AM
Wow! That works. Thank you, Princy.
Tags
AutoCompleteBox
Asked by
Roland Klug
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Roland Klug
Top achievements
Rank 1
LGFox
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Helen
Telerik team
Share this question
or