When we binding the data through web service in RadComboBox, web service method is not calling and data is not binding.
These are my following Code :
.aspx :
<script type="text/javascript">
var cb;
function cb_onDataBound(pComboboxItem, pDropDownLine) {
var customAttributes = pComboboxItem.get_attributes();
pDropDownLine.update(
'<span class="column" style="width:50px;">' + pComboboxItem.get_text().truncate(30, '[...]') + '</span>'
+ '<span class="column" style="width:50px;">' + customAttributes.getAttribute("Company") + '</span>'
+ '<span class="column" style="width:50px;">' + customAttributes.getAttribute("City") + '</span>'
);
}
function pageLoad(sender, args) {
initComboExtensions();
cb = $find("RadComboBox1");
cb.onDataBound = cb_onDataBound;
}
</script>
<telerik:RadComboBox runat="server"
ID="RadComboBox1"
Skin="Default"
Height="200px"
Width="200px"
DropDownWidth="200px"
ShowMoreResultsBox="true"
EnableVirtualScrolling="true"
ChangeTextOnKeyBoardNavigation="false"
OnClientItemsRequesting="OnClientItemsRequesting"
OnClientItemsRequested="OnClientItemsRequested"
OnClientDropDownOpening="OnClientDropDownOpening"
EnableLoadOnDemand="true">
<HeaderTemplate>
<ul style="list-style: none">
<li>
<span class="column" style="width: 50px;">ClientID</span>
<span class="column" style="width: 50px;">Company</span>
<span class="column" style="width: 50px;">City</span>
</li>
</ul>
</HeaderTemplate>
<WebServiceSettings Method="GetClientNames" Path="BindComboboxService.asmx" />
</telerik:RadComboBox>
.asmx :
[WebMethod]
public RadComboBoxData GetClientNames(RadComboBoxContext context)
{
DataTable data = objProjectBL.PopulateClientCombo();
List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems);
RadComboBoxData comboData = new RadComboBoxData();
try
{
int itemsPerRequest = 10;
int itemOffset = context.NumberOfItems;
int endOffset = itemOffset + itemsPerRequest;
if (endOffset > data.Rows.Count)
{
endOffset = data.Rows.Count;
}
if (endOffset == data.Rows.Count)
{
comboData.EndOfItems = true;
}
else
{
comboData.EndOfItems = false;
}
result = new List<RadComboBoxItemData>(endOffset - itemOffset);
for (int i = itemOffset; i < endOffset; i++)
{
RadComboBoxItemData itemData = new RadComboBoxItemData();
itemData.Text = data.Rows[i]["ClientID"].ToString();
itemData.Value = data.Rows[i]["ClientID"].ToString();
itemData.Attributes["Company"] = data.Rows[i]["Company"].ToString();
itemData.Attributes["City"] = data.Rows[i]["City"].ToString();
result.Add(itemData);
}
if (data.Rows.Count > 0)
{
comboData.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString());
}
else
{
comboData.Message = "No matches";
}
}
catch (Exception e)
{
comboData.Message = e.Message;
}
comboData.Items = result.ToArray();
return comboData;
}