I have a RadCombobox with EnableLoadingOnDemand enabled (Attached as bottom). I have a TemplateItem with a Checkbox included. Problem is when I try to get selected items on clientside it works fine only in first page.After that the items.get_count() which I am looping through increments (eg becomes more in increments as specified in the ItemsPerRequest), but the CheckBox item on new page defaults to 0, next one bocomes 1 etc, until next page where it repeats in same fasion.Thus this code does not work because the i in the loop becomes 0 for checkbox on new page (in this case the third record because ItemsPerRequest is set to 2).
Problem in short
This code : var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
Gives result of :ctl00_Content_MainBody_lstProductsTemplate_i0_chk1 (i becomes 0)
For each Checkbox at top of new page and gets incremented by 1 from there on eg ctl00_Content_MainBody_lstProductsTemplate_i1_chk1,ctl00_Content_MainBody_lstProductsTemplate_i2_chk1
The loop itself
for (var i = 0; i < items.get_count(); i++) {
Gets incremented correctly eg bocomes 4,6,8 etc
I am therefore getting error because this var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
gives me null value.
Pease help.
Thanks
function
onCheckBoxClick(chk) {
var combo = $find("<%= lstProductsTemplate.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 + recordCounterPerPage) + "_chk1");
var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
//if (chk1 != null) {
if (chk1.checked) {
text += item.get_text() +
",";
values += item.get_value() +
",";
}
//}
}
//remove the last comma from the string
text = removeLastComma(text);
values = removeLastComma(values);
alert(values);
if (text.length > 0) {
//set the text of the combobox
//combo.set_text(text);
}
else {
combo.set_text(
"");
}
}
<telerik:RadComboBox ID="lstProductsTemplate" runat="server" DataSourceID="dsGetProductSearch"
DataTextField="ProductName" DataValueField="ProductID" EmptyMessage="Start typing first characters of search here"
Height="450px" Width="650px" Skin="Web20" LoadingMessage="Loading search result..."
EnableAutomaticLoadOnDemand="True" ItemsPerRequest="2" ShowMoreResultsBox="True"
EnableVirtualScrolling="True" Sort="Ascending" ToolTip="Enter your search snipped to start (Set filter accordingly eg Contains or StartsWith)"
ZIndex="10001" OnClientItemsRequested="ItemsRequested">
<HeaderTemplate>
<table style="width: 440px" cellspacing="0" cellpadding="0">
<tr>
<td>
</td>
<td style="width: 400px;">
Product Name
</td>
<td style="width: 40px;">
StockOnHand
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table style="width: 440px" cellspacing="0" cellpadding="0">
<tr>
<td>
<div onclick="StopPropagation(event)">
<asp:CheckBox runat="server" ID="chk1" onclick="onCheckBoxClick(this)" />
</div>
</td>
<td style="width: 400px;">
<%
# Eval("ProductName")%>
</td>
<td style="width: 40px;">
<%
#Eval("StockOnHand")%>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadComboBox>