Bind CheckedItems

2 posts, 0 answers
  1. GD
    GD avatar
    29 posts
    Member since:
    Nov 2008

    Posted 03 Jan 2010 Link to this post

    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)

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 04 Jan 2010 Link to this post

    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.
Back to Top