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

Get items on codebehing

2 Answers 119 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Fabio PM
Top achievements
Rank 1
Iron
Fabio PM asked on 27 Aug 2020, 07:17 PM

Hi

I have a page with a radmultiselect. The items are populated using a webservice with the response in json format. All works fine.

I'm trying to get the items in code behind, but the RadMultiSelect.Items are aways null.

RadMultiSelect rms = area.FindControl("id_of_radmultiselect") as RadMultiSelect;
 
if (rms != null) {
    var selectedValues = rms.Value;
    foreach (string value in selectedValues) {
        MultiSelectItem selectedItem = rms.Items.FindChildByValue(value);
        string result = string.Format("Selected item with text: <strong>{0}</strong> and value: <strong>{1}</strong><br />", selectedItem.Text, selectedItem.Value);
    }
}

In my test I added two items and I get in the rms.Value the number 2.

But the rms.Items is always count = 0, and when I try to find chield by value the result are null.

Why the Value have two items and in the rms.Items is 0?

Thank you

2 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 27 Aug 2020, 07:35 PM

Hello Fabio,

As you have mentioned, the items are populated via web service. Which is why the items are not available on the server, as they should not be. If you need the items server-side, then the whole point of using the web-service on the client-side is missing. 

You can call the web service from the server and populate the items or just expose a method in the web service, that would give you the text of the items based on the value you pass to it.

As an alternative, before postback, you can get the selected items and serialize the needed info in a hidden field and on the server-side, you can deserialize the data and use it.

Regards,
Peter Milchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Fabio PM
Top achievements
Rank 1
Iron
answered on 28 Aug 2020, 12:28 PM

Thanks Peter

Understood. I will receive the value list and I need to get the text from my webservice or direct from the database.

The code are done!

Tags
MultiSelect
Asked by
Fabio PM
Top achievements
Rank 1
Iron
Answers by
Peter Milchev
Telerik team
Fabio PM
Top achievements
Rank 1
Iron
Share this question
or