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

RadComboBox Looping through ItemTemplate Items

1 Answer 316 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dirk
Top achievements
Rank 1
Dirk asked on 07 Sep 2010, 04:22 AM
Hi

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>

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Kalina
Telerik team
answered on 13 Sep 2010, 06:10 AM
Hi Dirk,

You are on the right way in your suppositions. Indeed you cannot loop and find the checkboxes within the template by iterating items.
I am afraid that using the ShowMoreResultsBox feature along with templates in RadComboBox is not officially supported. Let me suggest you remove the ShowMoreResultsBox and  ItemsPerRequest property settings from your RadComboBox definition.

All the best,
Kalina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Dirk
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Share this question
or