I need to pre load some data into a combo box and select an item, then use the load on demand functionality to add additional items (There are many dollar amount options, but usually a low one is selected so I don't want to take the hit of adding all of them unless I need to). If I don't preload it works fine, but when I load some data and then add more I seem to get the inital data added again and again. In the following example I get
1. numbers 1-10 loaded
2. numbers 1-20 added to the list
3. numbers 1-10 and then 31 - 40
Basically how can I prevent it from reloading the 1 - 10 items each time?? It seems to happen since it was created on page load
aspx
Code behind
1. numbers 1-10 loaded
2. numbers 1-20 added to the list
3. numbers 1-10 and then 31 - 40
Basically how can I prevent it from reloading the 1 - 10 items each time?? It seems to happen since it was created on page load
aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestHome.aspx.cs" Inherits="_Default" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> </telerik:RadScriptManager> <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="200px" Width="300px"> <telerik:RadComboBox ID="cbTest" runat="server" EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true" OnItemsRequested="cbTestItemsRequested"> </telerik:RadComboBox> </telerik:RadAjaxPanel> </div> </form></body></html>Code behind
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Data;using System.Configuration;using Telerik.Web.UI;public partial class _Default : System.Web.UI.Page { int _itemsPerRequest = 10; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { List<int> data = GetData(); for (int i = 0; i < 10; i++) cbTest.Items.Add(new RadComboBoxItem(data[i].ToString())); cbTest.FindItemByText("5").Selected = true; } } protected void cbTestItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e) { List<int> data = GetData(); int start = e.NumberOfItems; int count = _itemsPerRequest; if (count > data.Count - start) count = data.Count - start; var temp = data.Skip(start).Take(count); foreach (var v in temp) cbTest.Items.Add(new RadComboBoxItem(v.ToString())); if (start + count == data.Count) e.EndOfItems = true; } protected void OldcbTestItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e) { List<int> data = GetData (); int itemOffset = e.NumberOfItems; int endOffset = Math.Min(itemOffset + _itemsPerRequest, data.Count); e.EndOfItems = endOffset == data.Count; for (int i = itemOffset; i < endOffset; i++) cbTest.Items.Add(new RadComboBoxItem(data[i].ToString())); } private List<int> GetData() { List<int> results = new List<int>(50); for (int i = 1; i < 51; i++) { results.Add(i); } return results; }}