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

Remove Items on load

2 Answers 70 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Eric Klein
Top achievements
Rank 1
Eric Klein asked on 03 May 2011, 08:39 PM
I have two List boxes (Master and Child) on a screen that fill with data on load.  The first (Master) is loaded by looking at file stuctures and loading the names of all the files, the second (child) loads from a database and shows a list of files that have been previously selected. 

All works fine but what I want to do is on if the user selects a record that already has data in the database I want to remove the matching files from the Master List, so the file name should only show once in either the master or child listbox.

How do I remove items from the master on load.

2 Answers, 1 is accepted

Sort by
0
Gimmik
Top achievements
Rank 1
answered on 05 May 2011, 04:02 PM
Hi Eric,

I was playing with the client-side events for the RadListBox not too long ago. The OnClientLoad event can probably be used to do what you want. I would write a javascript function and call it from the OnClientLoad event of RadListBox2. The function would then take the contents of RadListBox2, iterate through them while removing them from RadListBox1. Since RadListBox2 should be a subset of RadListBox1, it would always find the matching item (unless it has been removed from the filesystem.) In the case the file was deleted, there wouldn't be a match - but you can make that event work in your favor too. In the event a match isn't found in RadListBox1, I would fire off a function to remove the item from RadListBox2 (since it's no longer valid) and also delete that entry from the database so it won't be an issue next time.

Here's a link to the documentation on the client-side OnClientLoad event:
http://www.telerik.com/help/aspnet-ajax/listbox-onclientload.html

Here's a link to the documentation on the client-side methods that you use to modify RadListBox1:
http://www.telerik.com/help/aspnet-ajax/listbox-client-object-api.html

I hope this helps!
-Gimmik
0
Genady Sergeev
Telerik team
answered on 06 May 2011, 10:18 AM
Hello Gimmik,

Both client-side and server-side item collections have remove method. You pass the item that you want to be removed to it. Here is an example (client side):

var rlb = $find("RadListBox1");
rlb.get_items().remove(rlb.findItemByText("item1"));


Best wishes,
Genady Sergeev
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
ListBox
Asked by
Eric Klein
Top achievements
Rank 1
Answers by
Gimmik
Top achievements
Rank 1
Genady Sergeev
Telerik team
Share this question
or