Hi,
I have a problem with my comboBoxes on the client side of my application. When I call [ComboBox].get_items() I get a collection of items as expected, but the items are empty. What I find odd is that if I navigate to the itemData property i can see that the value of the items are correct even though there is no text property.
The combobox is defined as follows:
<
telerik:RadComboBox
ID
=
"projectComboBox"
runat
=
"server"
DataSourceID
=
"ProjectSqlSource"
DataValueField
=
"project_id"
DataTextField
=
"Name"
/>
Hope you are able to help
Regards
Casper
17 Answers, 1 is accepted
[quote] It might be important to note that I've twp other RCBs configured in the same way and I can easily access the data in the code behind when it is posted back to the server[/quote]
Forgot to mention that I tested to see if I had the same problem on this page and I do, I just didn't notice this because the data from those RCBs is processed on the server.
You are using document.getElementById. This will return HTML element, but you need combobox object. Replace it with $find
function
newPlanShow(oWnd)
var
lol = $find(
"projectComboBox"
);
var
items = lol.get_items();
}
I hope this helps
Regards,
Hristo Valyavicharski
Telerik
See What's Next in App Development. Register for TelerikNEXT.
var lol = $find("<%= RadComboBoxProject.ClientID %>");
var items = lol.get_items();
Regards,
Hristo Valyavicharski
Telerik
See What's Next in App Development. Register for TelerikNEXT.
I still returns null.
I think I read somewhere that you can use the control property of the HTML object, which is why I tried that instead.
Do we have other options?
It is in a standard HTML table, it still returns null though.
<
table
>
<
tr
>
<
td
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RadComboBoxProject"
OnSelectedIndexChanged
=
"OnProjectTextChanged"
AutoPostBack
=
"True"
ChangeTextOnKeyBoardNavigation
=
"True"
DropDownAutoWidth
=
"Enabled"
EnableLoadOnDemand
=
"True"
Filter
=
"StartsWith"
DataSourceID
=
"ProjectSqlSource"
DataValueField
=
"project_id"
DataTextField
=
"Name"
OnClientDropDownOpening
=
"ProjectDropDownOpen"
>
<
DefaultItem
Text
=
"Choose project"
Value
=
"-1"
ViewStateMode
=
"Enabled"
/>
</
telerik:RadComboBox
>
</
td
>
<
td
>
<
telerik:RadComboBox
ID
=
"RadComboBoxPlan"
runat
=
"server"
AutoPostBack
=
"True"
OnSelectedIndexChanged
=
"OnPlanTextChanged"
ChangeTextOnKeyBoardNavigation
=
"True"
DropDownAutoWidth
=
"Enabled"
EnableLoadOnDemand
=
"True"
Filter
=
"StartsWith"
DataSourceID
=
"PlanSqlSource"
DataTextField
=
"name"
DataValueField
=
"plan_id"
OnItemsRequested
=
"RadComboBoxPlan_OnItemsRequested"
ViewStateMode
=
"Enabled"
>
<
DefaultItem
Text
=
"Choose plan"
Value
=
"-1"
/>
</
telerik:RadComboBox
>
</
td
>
<
td
>
<
telerik:RadButton
runat
=
"server"
ID
=
"newPlanDialog"
ToolTip
=
"Adds a new plan to the currently selected project"
Text
=
"Add new plan"
AutoPostBack
=
"False"
/>
</
td
>
</
tr
>
</
table
>
Attach sample project/page so we can debug your code.
Thanks.
Regards,
Hristo Valyavicharski
Telerik
See What's Next in App Development. Register for TelerikNEXT.
Thanks.
Regards,
Hristo Valyavicharski
Telerik
See What's Next in App Development. Register for TelerikNEXT.
Regards,
Hristo Valyavicharski
Telerik
See What's Next in App Development. Register for TelerikNEXT.
https://www.dropbox.com/s/xmvp9uzv8i0cp7c/TRS.zip?dl=0
The function is the first in the scripts.js and you should be able to see the problem if you just click "Add new plan"
Regards,
Hristo Valyavicharski
Telerik
I asked if you only wanted the code, because I am not allowed to post the database and you said yes. I have created a dummy database and changed the web.config to read from it. You should be able to download it from the same link as before.
Thanks a lot :)
Try to add the following js:
function
getComboById(id) {
var
combos = Telerik.Web.UI.RadComboBox.ComboBoxes;
for
(
var
i = 0; i < combos.length; i++) {
var
comboId = combos[i].get_id();
if
(comboId.includes(id) > -1) {
return
combos[i];
}
}
return
null
;
}
function
newPlanShow(oWnd) {
var
prj = getComboById(
"RadComboBoxProject"
);
}
Regards,
Hristo Valyavicharski
Telerik
The code for the .aspx-file cannot run. the .includes method is not supported by comboId.
I could however change the code to:
function getComboById(id) {
var combos = Telerik.Web.UI.RadComboBox.ComboBoxes;
for (var i = 0; i < combos.length; i++) {
var comboId = combos[i].get_id();
if (comboId === id) {
return combos[i];
}
}
return null;
}
To get the RCB object in the external file. i am now able to continue working.
Thank you very much for your help, it is much appreciated.
Kind regards
Casper