Hi,
I'm trying to get my radcombobox (populated with checkboxes) to show what items are selected. Its similar to this demo:
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/templates/defaultcs.aspx
However, my js code (copied from the above is simply returning empty strings with the .get_text() method.
Can anyone shed some light on why its returning nothing?
Live_Monitor.js
Anyone any ideas????
Thanks,
Sunny
I'm trying to get my radcombobox (populated with checkboxes) to show what items are selected. Its similar to this demo:
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/templates/defaultcs.aspx
However, my js code (copied from the above is simply returning empty strings with the .get_text() method.
Can anyone shed some light on why its returning nothing?
<
telerik:RadComboBox
ID
=
"RadComboBox_User_Type"
runat
=
"server"
EmptyMessage
=
"Select Users"
HighlightTemplatedItems
=
"true"
AllowCustomText
=
"true"
Width
=
"225px"
>
<
Items
>
<
telerik:RadComboBoxItem
ImagePath
=
"../Images/OnTime_Fkeys/Access Control.png"
Text_
=
"Employee"
>
</
telerik:RadComboBoxItem
>
<
telerik:RadComboBoxItem
ImagePath
=
"../Images/OnTime_Fkeys/Access Control.png"
Text_
=
"Visitor"
>
</
telerik:RadComboBoxItem
>
</
Items
>
<
ItemTemplate
>
<
div
onclick
=
"StopPropagation(event)"
style
=
"vertical-align: middle"
>
<
asp:CheckBox
runat
=
"server"
ID
=
"chk1"
Checked
=
"false"
/>
<
asp:Label
runat
=
"server"
ID
=
"Label1"
AssociatedControlID
=
"chk1"
>
<
img
src
=
'<%# DataBinder.Eval(Container, "Attributes['
ImagePath']") %>' alt="" style="vertical-align:text-top"/>
<%# DataBinder.Eval(Container, "Attributes['Text_']") %>
</
asp:Label
>
</
div
>
</
ItemTemplate
>
</
telerik:RadComboBox
>
protected
void
Page_Load(
object
sender, EventArgs e)
{
String script1 =
""
+
"function StopPropagation(e) "
+
"{"
+
"e.cancelBubble = true;"
+
"if (e.stopPropagation) "
+
"{"
+
"e.stopPropagation();"
+
"}"
+
"}"
;
ScriptManager.RegisterStartupScript(Page, Page.GetType(),
"LMP_Stop_Prop"
, script1,
true
);
ClientScript.RegisterClientScriptBlock(Page.GetType(),
"324nvik"
,
"<script src=\"../Javascript/Live_Monitor/Live_Monitor.js\" type=\"text/javascript\"></script>"
);
for
(
int
i = 0; i < RadComboBox_User_Type.Items.Count; i++)
{
RadComboBox_User_Type.Items[i].DataBind();
}
foreach
(RadComboBoxItem item
in
RadComboBox_User_Type.Items)
{
CheckBox chk = (CheckBox)item.FindControl(
"chk1"
);
chk.Attributes.Add(
"onclick"
,
"onCheckBoxClick(this)"
);
}
}
}
Live_Monitor.js
function
onCheckBoxClick(chk) {
var
combo = $find(
'RadComboBox_User_Type'
);
var
text =
""
;
var
values =
""
;
var
items = combo.get_items();
for
(
var
i = 0; i < items.get_count(); i++) {
var
item = items.getItem(i);
var
chk1 = $get(
"RadComboBox_User_Type"
+
"_i"
+ i +
"_chk1"
);
if
(chk1.checked) {
text += item.get_text() +
","
;
values += item.get_value() +
","
;
}
}
text = removeLastComma(text);
values = removeLastComma(values);
if
(text.length > 0) {
combo.set_text(text);
}
else
{
combo.set_text(
"Select Users"
);
}
}
function
removeLastComma(str) {
return
str.replace(/,$/,
""
);
}
Anyone any ideas????
Thanks,
Sunny