Set "Selected Item" in multiselect RadComboBox
Asked Answered
P

3

7

Is there any way we can set Selected Items or Checked Items in a multiselect RadComboBox ?. I want to set value on postback from server.

I tried following code but that works only if it is not a multiselect RadComboBox.

Radbox1.SelectedValue = "123"

My front end code.

<telerik:RadComboBox ID="Radbox1" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" Width="300" Height="200" AutoPostBack="True" OnSelectedIndexChanged="Radbox1_SelectedIndexChanged" />

I have value in Radbox1 which will be populated from database.

Thanks, Rahul

Pridgen answered 18/11, 2012 at 21:34 Comment(0)
S
10

When the Radcombobox is set to allow multiple selections via the checkboxes, you must use each items checked property.

I use a list here to simulate the items that I wish to have marked on postback. You could have this list pre-populated or it could even be loaded from a database:

enter image description here

Supat answered 19/11, 2012 at 7:18 Comment(0)
T
3
protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
{
    if ("YourString" == e.Item.Text))
    {
        e.Item.Checked = true;
    }
}

Or

protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
{
    List<String> yourStringList = new List<String>() {"string1","string2"};
    if (yourStringList.Contains(e.Item.Text))
    {
         e.Item.Checked = true;
    }
}
Tegucigalpa answered 23/5, 2013 at 11:14 Comment(0)
H
3

I've done something like this; Machine_Serial_Numbers is a telerik:RadComboBox;

foreach (var machine in bulletinData.Machines)
        {
            var comboItem = Machine_Serial_Numbers.FindItemByValue(machine.Id.ToString());

            if (comboItem != null)
            {
                comboItem.Checked = true;
            }                
        }

This worked for me.

enter image description here

Hefty answered 20/4, 2018 at 22:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.