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

Load items in Radcombobox on page load

1 Answer 383 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Vineet
Top achievements
Rank 1
Vineet asked on 13 Aug 2013, 04:38 PM
Hi,

I am using a radcombobox and populating it using webservice. However the combobox is not loaded when the page loads the first time. when i start typing the combobox gets loaded fine with the values. i want the combobox to contain top 100 rows when the page loads so that by just clicking on the dropdown arrow it can see the option with out typing anything in the box.
Please find my code below:-

<telerik:RadComboBox runat="server" ID="RadComboBox1" Width="300px" Height="550px" AllowCustomText="true" OnClientItemsRequesting="OnClientItemsRequesting"
                EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true" MarkFirstMatch="true" ItemsPerRequest="100"
                EnableAutomaticLoadOnDemand="true" AutoPostBack="true">
                <WebServiceSettings Path="~/Controls/ManagerListService.asmx" Method="GetManagerNames" />
            </telerik:RadComboBox>

javascript
function OnClientItemsRequesting(sender, eventArgs) {
        var context = eventArgs.get_context();
    }

web srevice code

 <WebMethod()>
    Public Function GetManagerNames(context As RadComboBoxContext) As RadComboBoxData
        Dim data As DataTable = Employee.LineManagersForUser(context.Text)

        Dim result As New List(Of RadComboBoxItemData)()
        Dim dropDownData As New RadComboBoxData()
        Dim itemOffset As Integer = context.NumberOfItems
        Dim endOffset As Integer = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count)
        dropDownData.EndOfItems = endOffset = data.Rows.Count

        result = New List(Of RadComboBoxItemData)(endOffset - itemOffset)

        For i As Integer = itemOffset To endOffset - 1
            Dim itemData As New RadComboBoxItemData()
            itemData.Text = data.Rows(i)("Name").ToString()
            itemData.Value = data.Rows(i)("EmplID").ToString()

            result.Add(itemData)
        Next

        dropDownData.Items = result.ToArray()
        Return dropDownData
    End Function


Thanks,
Vineet

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 16 Aug 2013, 01:40 PM
Hi Vineet,

 
Thank you for contacting Telerik support.

You can request the first items on pageLoad as for example it is done in the code below:

<script type="text/javascript">
           function pageLoad() {
 
               var combo = $find("<%=RadComboBox1.ClientID%>");
               combo.requestItems("");
           }
 
       </script>

Hope this will work for you. if you have further questions please don't hesitate to contact us again.

Regards,
Plamen
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
ComboBox
Asked by
Vineet
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or