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

Bind CheckedItems

1 Answer 74 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
GD
Top achievements
Rank 1
GD asked on 03 Jan 2010, 10:25 PM

Can I binding my obeject's property to CheckedItems?
The property can be List<int> (my DataValueField in int) or List<RadListBoxItem> or other.
I need on load the ListBox checked what there are in my property and on save I need in my property there are checked items.

is it possibile?

(I'm sorry fot my bad english)

1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 04 Jan 2010, 06:29 PM
Hi Claudio,

You can use the following code:

<telerik:RadListBox runat="server" ID="RadListBox1" CheckBoxes="true">
    </telerik:RadListBox>

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            for (int i = 0; i < 9; i++)
            {
                int shouldBeChecked = i % 2;
                RadListBoxItem item = new RadListBoxItem("Text " + i.ToString(), shouldBeChecked.ToString());
                RadListBox1.Items.Add(item);
 
            }
 
            RadListBox1.DataBind();
        }
 
        foreach (RadListBoxItem item in RadListBox1.Items)
        {
            if (int.Parse(item.Value) == 0)
            {
                item.Checked = true;
            }
        }
    }

This will make all items with value equal to 0 checked. In this case, these are all even items. You can implement your own logic to change this behavior.


Greetings,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ListBox
Asked by
GD
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or