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

Load on Demand - Repeat Items

6 Answers 81 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Curtis Robinson
Top achievements
Rank 1
Curtis Robinson asked on 08 Aug 2008, 07:07 PM
I am using Load on Demand with ShowMoreResults and I am binding to the combobox on the intitial Page_Load so the first page of results is in the combobox before a user actually requests them. I am pretty sure that this initial binding on the page_load is what is causing the problem, but it is necessary for my requirements.

When I click the more results button, the ItemsRequested event is fired off and I add more items to the combobox. When the results are finished being loaded into the combobox, I get the original first page of results with the second page after it, then the first page of results again.

Why am I getting these repeat items? How can I stop these repeat items from being added. It has something to do with the fact that I am making this initial load. I noticed when the ItemsRequested event gets called and I don't make that initial load, the combobox.items.count always starts off at 0 when the ItemsRequested event begins, but when I make that initial load, the count is always the size of my first page 100 when it begins.

Here is my aspx code for the combobox:
<telerik:RadComboBox ID="testDdl" runat="server" Width="350px" Height="200px" DataTextField="DocumentId" DataValueField="MainId" Skin="Outlook" AllowCustomText="true" ShowToggleImage="true" MarkFirstMatch="true" OnItemsRequested="TestDdl_ItemsRequested" EnableLoadOnDemand="true" ShowMoreResultsBox="true" /> 
 

Here is my page load event:

protected void Page_Load(object sender, EventArgs e)  
{  
   Documents testDocuments = new Documents();  
     
   for (int i = 0; i < 100; i++)  
   {  
      Document document = new Document();  
      document.DocumentId = i.ToString();  
      document.MainId = i;  
      testDocuments.Add(document);  
   }  
 
   testDdl.DataSource = testDocuments;  
   testDdl.DataBind();  

Here is my ItemsRequested event: 

protected void TestDdl_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)  
{  
   int myTotalRecordCount = 1000;  
 
   const int itemsPerRequest = comparisonSetPageSize;  
   int itemOffset = e.NumberOfItems;  
   int endOffset = itemOffset + itemsPerRequest;  
 
   if (endOffset > myTotalRecordCount)  
   {  
      endOffset = myTotalRecordCount;  
   }  
 
   e.EndOfItems = endOffset == myTotalRecordCount;  
 
   for (int i = itemOffset; i < endOffset; i++)  
   {  
      RadComboBoxItem newnewItem = new RadComboBoxItem(i.ToString(), i.ToString());  
 
      testDdl.Items.Add(newItem);  
   }  
 
   e.Message = "Items 1 - " + endOffset + " of " + myTotalRecordCount;  

6 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 11 Aug 2008, 11:01 AM
Hi Kelly,

Thank you for contacting us.

I suggest you add the following code line:

testDdl.Items.Clear(); 

in the TestDdl_ItemsRequested method, before you add the new RadComboBox items.

All the best,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Curtis Robinson
Top achievements
Rank 1
answered on 14 Aug 2008, 03:48 PM
that doesn't work. i rewrote my application so it doesn't depend on telerik controls for anything other than displaying information, so this is no longer an issue.

Thanks
0
kiran
Top achievements
Rank 1
answered on 15 Sep 2008, 06:01 AM
Hi Kelly Cunningham

    Did u get any solution for this problem?
    
Thanks
0
Yana
Telerik team
answered on 15 Sep 2008, 07:17 AM
Hi Kiran,

Please check the attached sample project which shows the needed approach.

Hope it helps.

Regards,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Antoinette Martinez
Top achievements
Rank 1
answered on 08 Jan 2009, 11:06 PM
It is a very frustrating that you must do an add to the RadComboBox rather then just rebinding to the data you need. A clear of items should at least work so that you can start from a clear slate.

   for (int i = itemOffset; i < endOffset; i++)  
   {  
      RadComboBoxItem newnewItem = new RadComboBoxItem(i.ToString(), i.ToString());  
 
      testDdl.Items.Add(newItem);  
   }
should not be necessary. You are already hitting the data base and returning all the items you need; you should just be able to set the datasource and rebind.
RadComboBox1.DataSource = List<ListItems>
RadComboBox1.DataBind();

The inability to handle this is bad design in my opinion.


0
Veselin Vasilev
Telerik team
answered on 09 Jan 2009, 09:19 AM
Hello Antoinette Martinez,

Setting the DataSource and then rebinding the combobox in ItemsRequested event will work fine.
And, of course, there will be no need to add the items manually one by one.

Let us know if you have any problem with this implementation.

Regards,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Curtis Robinson
Top achievements
Rank 1
Answers by
Yana
Telerik team
Curtis Robinson
Top achievements
Rank 1
kiran
Top achievements
Rank 1
Antoinette Martinez
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or