Find ID of selected item from Listbox

0 Answers 225 Views
ListBox
Danielle
Top achievements
Rank 1
Iron
Iron
Danielle asked on 14 Mar 2023, 01:17 PM
I'm using two related listboxes to transfer data from one list to another.  In my backend, when I reference Request.Form["lstAssociated"] I can get a list of the id's from the listbox that contains the item I selected to send to the other list, however, I don't see anywhere in the data how I can obtain the ID of just the item I have selected.  We are using Razor forms.
Georgi
Telerik team
commented on 17 Mar 2023, 08:25 AM

Hi Danielle,

The selected state is solely visual. We highlight the dom element using CSS.

If I understand correctly, you would like to know which elements moved from one listbox to another. Please correct me if I am wrong.

Is it an option to compare the previous state of the listboxes before the user modified them to the submitted data, hence obtaining the relocated items?

Danielle
Top achievements
Rank 1
Iron
Iron
commented on 17 Mar 2023, 11:42 AM

Yes, I supposed I could, I just assumed there would be an event I could tie into which would contain the information of the item being moved.  If not, I will code something like you have described.


Thanks for your help.

Georgi
Telerik team
commented on 20 Mar 2023, 06:42 AM

Hi Danielle,

Another option you have is to store the ids of items that change position in a hidden input and then extract the ids from the payload of the request.

Danielle
Top achievements
Rank 1
Iron
Iron
commented on 20 Mar 2023, 12:00 PM

Thanks Georgi. How would I get those ids of the items that changed position?  Or are you saying to store the original values in a hidden input and then compare them on Submit?
Georgi
Telerik team
commented on 21 Mar 2023, 07:48 AM

You could get the id of the element that changed position and store it in a hidden input within the Add/Remove event handlers.

e.g.

// listbox config            
.Events(events => events
                .Add("onAdd")
                .Remove("onRemove")
            )

function onRemove(e) {  // e.items is an array that contains all removed items
  // store the ids of removed items here
}

No answers yet. Maybe you can help?

Tags
ListBox
Asked by
Danielle
Top achievements
Rank 1
Iron
Iron
Share this question
or