请尝试使用以下代码片段。
.ASPX
<telerik:RadComboBox ID="ddlEducationPeriod" runat="server" EmptyMessage="--Select education period--"
HighlightTemplatedItems="true" SkinID="DropDownList194*200" AllowCustomText="true">
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" onClick="EducationHeaderCheckChanged();" />
<asp:Label runat="server" ID="lblTeacherSelectAll" Text="Select All" AssociatedControlID="chkSelectAll"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<div onclick="StopPropagation(event)">
<asp:CheckBox runat="server" ID="chkddlID" onclick="onCheckBoxClickEducation(this)"
Text='<%#Eval("Name") %>' />
<asp:Label runat="server" ID="labelddlID" Text='<%#Eval("ID") %>' Visible="false"></asp:Label>
</div>
</ItemTemplate>
</telerik:RadComboBox>
.ASPX.CS
protected void Page_Load(object sender, EventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="aaa"},
new { ID = 2, Name = "bbb"},
new { ID = 3, Name = "ccc"},
new { ID = 4, Name = "ddd"},
new { ID = 5, Name ="eee"},
new { ID = 6, Name ="aaa"},
new { ID = 7, Name = "bbb"},
new { ID = 8, Name = "ccc"},
new { ID = 9, Name = "ddd"},
new { ID = 10, Name ="eee"}
};
ddlEducationPeriod.DataSource = data;
ddlEducationPeriod.DataTextField = "Name";
ddlEducationPeriod.DataValueField = "ID";
ddlEducationPeriod.DataBind();
}
JAVASCRIPT
function onCheckBoxClickEducation(chk) {
var combo = $find("<%= ddlEducationPeriod.ClientID %>");
//prevent second combo from closing
cancelDropDownClosing = true;
//holds the text of all checked items
var text = "";
//holds the values of all checked items
var values = "";
//get the collection of all items
var items = combo.get_items();
//enumerate all items
for (var i = 0; i < items.get_count(); i++) {
var item = items.getItem(i);
//get the checkbox element of the current item
var chk1 = $get(combo.get_id() + "_i" + i + "_chkddlID");
if (chk1.checked) {
text += item.get_text() + ", ";
values += item.get_value() + ",";
}
}
//remove the last comma from the string
text = removeLastComma(text);
values = removeLastComma(values);
if (text.length > 0) {
//set the text of the combobox
combo.set_text(text);
//update the treeview in the second combobox
}
else {
//all checkboxes are unchecked
//so reset the controls
combo.set_text("");
}
}
function StopPropagation(e) {
e.cancelBubble = true;
if (e.stopPropagation) {
e.stopPropagation();
}
}
function EducationHeaderCheckChanged() {
var headerchk = document.getElementById('ddlEducationPeriod_Header_chkSelectAll');
onCheckBoxClickSelectAll(headerchk.checked, "ddlEducationPeriod");
}
function onCheckBoxClickSelectAll(headerchk, combo) {
var combo = $find("<%= ddlEducationPeriod.ClientID %>");
cancelDropDownClosing = true;
//holds the text of all checked items
var text = "";
//holds the values of all checked items
var values = "";
//get the collection of all items
//enumerate all items
var items = combo.get_items();
for (var i = 0; i < items.get_count(); i++) {
var item = items.getItem(i);
//get the checkbox element of the current item
var chk1 = $get(combo.get_id() + "_i" + i + "_chkddlID");
chk1.checked = headerchk;
if (chk1.checked) {
text += item.get_text() + ", ";
values += item.get_value() + ",";
}
}
//remove the last comma from the string
text = removeLastComma(text);
values = removeLastComma(values);
if (text.length > 0) {
//set the text of the combobox
combo.set_text(text);
}
else {
//all checkboxes are unchecked
//so reset the controls
combo.set_text("");
}
}
function removeLastComma(str) {
return str.slice(0, -2);
}