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

Binding Listviews Checkbox Checked value

1 Answer 121 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 22 Mar 2011, 01:40 PM
Greetings,

I have been racking my brain and I think that this is probably something silly that I am missing. I have to generate a list of employee "requirements" in the form of checkboxes. I am databinding them to a database with the following fields:

OptionID (unique Identifier)
Name (for the display of the checkbox)
Checked (a bit)

Am I misunderstanding the Listbox behavior in that I would like to display the text field on a checkbox, with a "value" behind it, and then databind whether or not the checkbox should be checked?

Please also note that I can (and did) create a template field with a checkbox in it, but these checkboxes do not behave the way I would like them to when using the following code from the intro to listboxes:

 

StringBuilder sb = new StringBuilder(); 
IList<RadListBoxItem> collection =RadListBox1.CheckedItems; 
foreach (RadListBoxItem item in collection) 
{
  
    sb.Append(item.Value +  "<br />"); 
}

 

The checked box in the template is not counting towards the checked value of the list item.

I am jsut trying to cut down on code, because if I wanted to cycle through each item and manually check if it should be checked, I could do that using a radiobutton list.

I am using Visual Studio 2010 with radcontrols for asp.net ajax Q2 2010 NET40.

Thanks,

Thomas Turner

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar Terziev
Telerik team
answered on 25 Mar 2011, 04:01 PM
Hello Thomas,

I've prepared a sample page demonstrating how to get the checked values from a data bound listbox. In this example page there are two listboxes, one using the default CheckBox functionality, and one having templated CheckBox control in it.

I hope this would help you out.

All the best,
Dimitar Terziev
the Telerik team
Tags
ListBox
Asked by
Thomas
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Share this question
or