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

RadMultiSelect select value programmatically

5 Answers 1202 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 06 Feb 2020, 07:33 AM

Hello

I somehow can't find a way to programmatically set selected values of RadMultiSelect when page opening on the server.
Can you help me?
Thank you.

5 Answers, 1 is accepted

Sort by
0
Accepted
Peter Milchev
Telerik team
answered on 10 Feb 2020, 09:55 AM

Hello Igor,

The type of the value is an object array, which contains multiple values. So, you can set the value as follows:

<telerik:RadMultiSelect ID="RadMultiSelect1" DataTextField="MyText" DataValueField="MyValue" runat="server" RenderMode="Lightweight">
</telerik:RadMultiSelect>

protected void Page_Init(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        RadMultiSelect1.DataSource = Enumerable.Range(1, 10).Select(x => new
        {
            MyText = "Item #" + x,
            MyValue = x
        });
        RadMultiSelect1.DataBind();


        // set value
        RadMultiSelect1.Value = new object[] { 3, 5 };
    }
}

As a token of gratitude for bringing to our attention that this information is missing in our docs, I have updated your Telerik points.

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Igor
Top achievements
Rank 1
answered on 10 Feb 2020, 12:08 PM

So, you need to convert Datasource to the array. For example:

RadMultiSelect1.Value = dataTable.Rows.OfType<DataRow>().Select(k => k.Field<String>("USER_LOGIN")).ToArray();

Thank you.

PS. In regard to docs, your client event links are pointed from aspnet to kedno.

https://docs.telerik.com/devtools/aspnet-ajax/controls/multiselect/client-side-programming/events#examples

0
Peter Milchev
Telerik team
answered on 12 Feb 2020, 08:31 PM

Hello Igor,

Thank you for sharing this, but in this case, it is intentional, because the RadMultiSelect is a server wrapper of the Kendo UI MultiSelect widget, hence the events are the same.

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Alan
Top achievements
Rank 1
answered on 20 Nov 2020, 05:19 PM

How do you set initial value(s) if datasource is a datatable?

 

RadMultiSelect1.DataSource = dtStatus ;

RadMultiSelect1.Value = (value1, value2) ????

 

0
Peter Milchev
Telerik team
answered on 25 Nov 2020, 03:08 PM

Hello Alan, 

The value property of the MultiSelect is an array of objects. It contains all the values that are selected in the MultiSelect. There is an example of that in the Virtualization demo as well as in my initial post in this thread:

The important thing is that the Value property array contains only the values of your selected items, not the texts or other fields. 

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/.

Tags
MultiSelect
Asked by
Igor
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Igor
Top achievements
Rank 1
Alan
Top achievements
Rank 1
Share this question
or