hi, I have following JSON string but unable to bind it :
JSON string :
var result ="{\"GroupDispositions\":[{\"Code\":\"C\",\"Description\":\"CONTACTED\"},{\"Code\":\"NC\",\"Description\":\"NOT CONTACTED\"}],\"Response\":[{\"ResultCode\":\"0\",\"ResultString\":\"Pass\"}]}";
Here is my Code:
function OnSuccess_FillDispositions(result) {
try {
if (result == null)
return;
var items = result.d || result;
var combo = $find('<%=cmbMainDisposition.ClientID %>');
var combosubsub = $find("<%= cmbSubSubDisposition.ClientID %>");
// alert(combo);
if (combo != null) {
combo.clearItems();
combosubsub.clearItems();
combosubsub.clearSelection();
for (var rowIndex = 0; rowIndex < result.length; rowIndex++) {
var row = result[rowIndex];
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_value(row.Code);
comboItem.set_text(row.Description);
comboItem.get_attributes().setAttribute("Code", row.Code);
combo.get_items().add(comboItem);
}
}
combo.get_items().getItem(0).select();
}
Try parsing the Json to javascript object and then loop thorugh GroupDispostion array to access code and descriptions
Try with below code
function OnSuccess_FillDispositions(result) {
try {
if (result == null)
return;
var items = result.d || result;
var combo = $find('<%=cmbMainDisposition.ClientID %>');
var combosubsub = $find("<%= cmbSubSubDisposition.ClientID %>");
// alert(combo);
if (combo != null) {
combo.clearItems();
combosubsub.clearItems();
combosubsub.clearSelection();
//Parse the Json string
var parsedResult = JSON.parse(result);
//Loop through GroupDispositions and assign the value
for (var rowIndex = 0; rowIndex <= parsedResult.GroupDispositions.length; rowIndex++) {
var row = result[rowIndex];
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_value(parsedResult.GroupDispositions[rowIndex].Code);
comboItem.set_text(parsedResult.GroupDispositions[rowIndex].Description);
comboItem.get_attributes().setAttribute("Code", parsedResult.GroupDispositions[rowIndex].Code);
combo.get_items().add(comboItem);
}
}
combo.get_items().getItem(0).select();
}
Member
31 Points
188 Posts
How bind RadDropDown to a complex Json string
Nov 05, 2018 10:38 AM|shashikant2011|LINK
hi, I have following JSON string but unable to bind it :
JSON string :
Here is my Code:
Please help!
All-Star
50841 Points
9895 Posts
Re: How bind RadDropDown to a complex Json string
Nov 06, 2018 06:53 PM|A2H|LINK
Try parsing the Json to javascript object and then loop thorugh GroupDispostion array to access code and descriptions
Try with below code
Aje
My Blog | Dotnet Funda