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

DataBinding issue in RadComboBox through WebService

3 Answers 83 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Anjan
Top achievements
Rank 1
Anjan asked on 02 Nov 2015, 02:30 PM

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;
        }​

3 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 05 Nov 2015, 08:12 AM
Hi,

I tested the provided code, and after I removed the dependencies to the underlying data layer, the combobox is working properly. I've attached the sample page I used for testing. Could you verify if it's working on your end as well?

Regards,
Bozhidar
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Anjan
Top achievements
Rank 1
answered on 05 Nov 2015, 02:09 PM

Hi, 

It is working your code. But my scenario is different. I need to populate multiple column in RadComboBox. Please help that one.

0
Bozhidar
Telerik team
answered on 10 Nov 2015, 08:02 AM
Hi,

In order to help you with your specific scenario, we would need the relevant code. Please send us the modifications needed to the sample I send you, so that we can troubleshoot the exact case.

Regards,
Bozhidar
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Anjan
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Anjan
Top achievements
Rank 1
Share this question
or