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

Radcombox -There was error in callback

7 Answers 511 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Naga
Top achievements
Rank 1
Naga asked on 26 Dec 2013, 05:23 AM
Dynamically created ComboBox and Load-on-demand not working .

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Dec 2013, 06:33 AM
Hi Naga,

Please have a look into the following C# code snippet which works fine at my end.

C#:
protected void Page_Load(object sender, EventArgs e)
{
    Telerik.Web.UI.RadComboBox combo =new Telerik.Web.UI.RadComboBox();
    combo.ID = "RadComboBox1";
    combo.AutoPostBack = true;
    combo.EmptyMessage = "Select";
    combo.EnableLoadOnDemand = true;
    combo.ItemsRequested += new Telerik.Web.UI.RadComboBoxItemsRequestedEventHandler(combo_ItemsRequested);
    form1.Controls.Add(combo);
}
void combo_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
    Telerik.Web.UI.RadComboBox combo = (Telerik.Web.UI.RadComboBox)sender;
    String connstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(connstring);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand("SELECT Cityname from City ", conn);
    DataTable data = new DataTable();
    conn.Open();
    try
    {
        adapter.Fill(data);
        combo.DataSource = data;
        combo.DataTextField = "Cityname";
        combo.DataBind();
    }
    finally
    {
        conn.Close();
    }
}

Let me know if you have any concern.
Thanks,
Shinu.
0
Naga
Top achievements
Rank 1
answered on 02 Jan 2014, 04:39 AM
Static radcombox load on demand is working fine,Dynamic Rad combobox load on demand not working.
We are using telerik(2013.3.1114.45)version in visual studio 2012.

Dynamic Rad combobox load on demand time,Iam getting "There was error in callback" this error.
0
Shinu
Top achievements
Rank 2
answered on 02 Jan 2014, 06:18 AM
Hi Naga,

Please have a look into the following forum thread which deals the same issue. Please provide your code if it doesn't help.

Load On Demand and Exception handling.
Server Error in the ItemRequest Event.

Thanks,
Shinu.

0
Naga
Top achievements
Rank 1
answered on 02 Jan 2014, 06:53 AM


Hi Shinu,



          Please check error .verify the below mentioned code also.



public void InstantiateIn(System.Web.UI.Control container)
            {

                combo = new RadComboBox();
                combo.ID = colname;

                combo.AutoPostBack = true;
                combo.AppendDataBoundItems = true;
                combo.AllowCustomText = true;
                combo.CheckBoxes = true;
                combo.AutoPostBack = true;
                combo.EnableCheckAllItemsCheckBox = true;

                combo.CheckedItemsTexts = RadComboBoxCheckedItemsTexts.DisplayAllInInput;
                combo.MarkFirstMatch = true;
                combo.HighlightTemplatedItems = true;
                combo.EmptyMessage = "All";
                combo.NoWrap = false;
                combo.CssClass = "target-users-popup-dropdown";
                combo.DropDownCssClass = "target-users-popup-dropdown-1";
                combo.Localization.AllItemsCheckedString = "All";
                combo.Localization.CheckAllString = "All";
                combo.OnClientDropDownClosing = "ShowModalPopup";
                combo.PreRender += new EventHandler(combo_PreRender);
                combo.EnableLoadOnDemand = true;
               combo.ShowMoreResultsBox = true;
                 combo.ItemsPerRequest=10;
                 combo.EnableVirtualScrolling = true;
                combo.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(l_SelectedIndexChanged);
                combo.ItemDataBound += new RadComboBoxItemEventHandler(combo_ItemDataBound);
               combo.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(combo_ItemsRequested);
                combo.DataValueField = colname;
                combo.DataTextField = colname;
                combo.DataBind();
                container.Controls.Add(combo);

            }

            void combo_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
            {
                int ItemsPerRequest = 10;

                RadComboBox combo = (RadComboBox)sender;
                if (combo != null)
                {

                    int itemOffset = e.NumberOfItems;
             );
                    List<string> data = GetUserProfieColumnData(combo.DataValueField, itemOffset, ItemsPerRequest);

                    e.EndOfItems = ItemsPerRequest > data.Count;

                    for (int i = 0; i < data.Count; i++)
                    {
                                        combo.Items.Add(new RadComboBoxItem(data[i].ToString(), data[i].ToString()));

                    }

                  
                    obj.ComboPrerender(sender, e);

                }
            }

0
Shinu
Top achievements
Rank 2
answered on 03 Jan 2014, 02:44 AM
Hi  Naga,

Please try the following code snippet which works fine at my end.

C#:
protected void Page_Load(object sender, EventArgs e)
{
    Telerik.Web.UI.RadComboBox combo;
    string colname = "CompanyName";
    combo = new RadComboBox();
    combo.ID = colname;
 
    combo.AutoPostBack = true;
    combo.AppendDataBoundItems = true;
    combo.AllowCustomText = true;
    combo.CheckBoxes = true;
    combo.AutoPostBack = true;
    combo.EnableCheckAllItemsCheckBox = true;
 
    combo.CheckedItemsTexts = RadComboBoxCheckedItemsTexts.DisplayAllInInput;
    combo.MarkFirstMatch = true;
    combo.HighlightTemplatedItems = true;
    combo.EmptyMessage = "All";
    combo.NoWrap = false;
    combo.CssClass = "target-users-popup-dropdown";
    combo.DropDownCssClass = "target-users-popup-dropdown-1";
    combo.Localization.AllItemsCheckedString = "All";
    combo.Localization.CheckAllString = "All";
    combo.EnableLoadOnDemand = true;
    combo.ShowMoreResultsBox = true;
    combo.ItemsPerRequest = 10;
    combo.EnableVirtualScrolling = true;
    combo.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(combo_ItemsRequested);
    combo.DataValueField = colname;
    combo.DataTextField = colname;
    combo.DataBind();
    form1.Controls.Add(combo);
}
void combo_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    DataTable data = GetData(e.Text);
    int itemOffset = e.NumberOfItems;
    int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
    e.EndOfItems = endOffset == data.Rows.Count;
 
    for (int i = itemOffset; i < endOffset; i++)
    {
        combo.Items.Add(new RadComboBoxItem(data.Rows[i]["CompanyName"].ToString(), data.Rows[i]["CompanyName"].ToString()));
    }
    e.Message = GetStatusMessage(endOffset, data.Rows.Count);
}
private static DataTable GetData(string text)
{
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from Customers ", ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
    DataTable data = new DataTable();
    adapter.Fill(data);
    return data;
}
private static string GetStatusMessage(int offset, int total)
{
    if (total <= 0)
        return "No matches";
    return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total);
}

Hope this will helps you.
Thanks,
Shinu.
0
Naga
Top achievements
Rank 1
answered on 03 Jan 2014, 08:02 AM
What is the difference in code?

0
Shinu
Top achievements
Rank 2
answered on 06 Jan 2014, 03:14 AM
Hi Naga,

In my code OnItemRequestedEvent I am trying to access all the data from the table and adding items to the RadComboBox based on the current itemoffset and endoffset values. So first it will add only 10 items to the RadComboBox and then from 10 to 20 items and so on. The GetStatusMessage is used to display the status of the RadComboBoxItems.

Thanks,
Shinu.
Tags
ComboBox
Asked by
Naga
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Naga
Top achievements
Rank 1
Share this question
or