You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This class represents the individual item of a RadCheckBoxList or RadRadioButtonList. You can use the methods to get the current state of the items, or to set it. Note, however, that changes are not sent to the server or persisted after a postback. The only exception is the set_selected() method that can select or deselect an item.
Copy file name to clipboardExpand all lines: controls/checkboxlist/functionality/select-item.md
+48-4Lines changed: 48 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,9 +103,11 @@ End Sub
103
103
104
104
## Get Selected Item Server Side
105
105
106
-
To get the selected item and selected index you can use the `SelectedItem`and `SelectedIndex` properties of the **RadCheckBoxList** control.
106
+
To get all selected items, you can loop over the `Items` collection and check for the item's `Selected` property.
107
107
108
-
>caption Example 4: Get `SelectedIndex` and `SelectedItem` of the **RadCheckBoxList** from the code behind.
108
+
To get the first selected item and first selected index you can use the `SelectedItem` and `SelectedIndex` properties of the **RadCheckBoxList** control.
109
+
110
+
>caption Example 4: Get the selected items of the **RadCheckBoxList** from the code behind.
The selected item reference provides all its properties (e.g., `Value`, `Text`, `Selected` and `Enabled`).
154
+
The `SelectedItem` reference provides all its properties (e.g., `Value`, `Text`, `Selected` and `Enabled`).
135
155
136
156
137
157
## Select Item Client Side
138
158
139
159
You can select a particular item of a **RadCheckBoxList** by passing the corresponding index in the `set_selectedIndex()` method of the control.
140
160
161
+
Another approach is to loop through the items via the `get_items()` method and use the `set_selected()` method each [Telerik.Web.UI.ButtonListItem]({%slug Telerik.Web.UI.ButtonListItem%}) item provides.
162
+
141
163
>caption Example 6: Select an item on the client side.
142
164
143
165
````JavaScript
144
166
var checkboxlist =$find("<%=RadCheckBoxList1.ClientID%>");
167
+
//select item by index
145
168
checkboxlist.set_selectedIndex(0);
169
+
170
+
//select item by another condition via its own methods
171
+
var items =checkboxlist.get_items();
172
+
for (var i =0; i <items.length; i++) {
173
+
if (items[i].get_text() =="Item 3") {
174
+
items[i].set_selected(true);
175
+
}
176
+
else {
177
+
items[i].set_selected(false);
178
+
}
179
+
}
146
180
````
147
181
148
182
149
183
## Get Selected Item Client Side
150
184
151
-
You can obtain the items, selected item and selected item index of **RadCheckBoxList** through the `get_items()`, `get_selectedItem()`, and `get_selectedIndex()` methods.
185
+
You can obtain the selected items, first selected item and first selected item index of **RadCheckBoxList** through the `get_selectedItems()`, `get_selectedItem()`, and `get_selectedIndex()` methods.
186
+
187
+
The `get_selectedItems()` method returns an array of [Telerik.Web.UI.ButtonListItem]({%slug Telerik.Web.UI.ButtonListItem%}) items.
188
+
189
+
The `get_selectedIndices()` method provides an array of numbers that correspond to the indexes of the selected items.
152
190
153
191
>caption Example 7: Reference items, selected item and selected index of the **RadCheckBoxList** through its client-side API.
154
192
155
193
````JavaScript
156
194
var checkboxlist =$find("<%=RadCheckBoxList1.ClientID%>");
157
195
var items =checkboxlist.get_items();
196
+
//loop over all the items and use their selected state
197
+
var selItems =cbl.get_selectedItems();
198
+
for (var i =0; i <selItems.length; i++) {
199
+
console.log(String.format("text: {0} with value: {1}", selItems[i].get_text(), selItems[i].get_value()));
200
+
}
201
+
//get the first selected item
158
202
var selectedItem =checkboxlist.get_selectedItem();
159
203
var selectedIndex =checkboxlist.get_selectedIndex();
0 commit comments