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

Binding Checkboxes in the list

2 Answers 208 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Vassili King
Top achievements
Rank 1
Vassili King asked on 06 May 2010, 10:53 PM
Hi,

I'm using a RadListBox with CheckBoxes option turned on. I bind the listbox to a table in a DataSet based on an event. The DataSet contains name, id and a bit flag per record (i.e., each row in the datatable would look similar to this:  "1", "Joe", true). I set Text and Value using DataTextField and DataValueField respectively. However, I can't seem to find a way to bind the checkboxes. Any ideas?

Thank you!

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 May 2010, 08:13 AM

H Vassil,

One suggestion would be accessing the DataItem in ItemDatBound event of the RadListBox and explicitly setting the Checked property. Here is an example.

C#:

 
    protected void RadListBox1_ItemDataBound(object sender, Telerik.Web.UI.RadListBoxItemEventArgs e)  
    {  
        RadListBoxItem item = (RadListBoxItem)e.Item;  
        DataRowView row = (DataRowView)item.DataItem;  
        if(Convert.ToBoolean(row["Flag"]))  // Check for the value returned  
        {  
            item.Checked = true;  
        }  
    } 

-Shinu.

0
Vassili King
Top achievements
Rank 1
answered on 07 May 2010, 03:59 PM
Thanks!
This worked just fine.
Tags
ListBox
Asked by
Vassili King
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Vassili King
Top achievements
Rank 1
Share this question
or