Management of many records

7 posts, 0 answers
  1. Fabio Cirillo
    Fabio Cirillo avatar
    181 posts
    Member since:
    Jan 2010

    Posted 14 Nov 2012 Link to this post

    Hi,
    since the sql select using the radcombox charged over 1000 records, you can upload a video, when I open the radcombobox, only 10 records at a time? And then you decide to continue to view other records.
    Maybe I need to use the property ShowMoreresultsBox = True?
    My side code vb net is:

    Protected Sub RadComboBox1_ItemsRequested(sender As Object, e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles RadComboBox1.ItemsRequested
     
    Dim sqlSelectCommand As String = "SELECT [id], [descrizione] from [tab_categorie] WHERE [descrizione] LIKE @desc + '%' Order By [descrizione]"
      
    Dim adapter As New SqlDataAdapter(sqlSelectCommand, ConfigurationManager.ConnectionStrings("TrycontactString").ConnectionString)
     
     adapter.SelectCommand.Parameters.AddWithValue("@desc", e.Text)
     
     Dim dataTable As New DataTable()
     
     adapter.Fill(dataTable)
     For Each dataRow As DataRow In dataTable.Rows
     
     Dim item As New RadComboBoxItem()
     
     item.Text = DirectCast(dataRow("descrizione"), String)
     
    item.Value=dataRow("id").ToString()radComboBox1.Items.Add(item)
     
     item.DataBind()
     
     Next
    End Sub

     

     

     

    While the ASP side code is:

    <telerik:RadComboBox ID="RadComboBox1" Runat="server" DropDownWidth="325px"
        EmptyMessage="Choose a Catogory" EnableLoadOnDemand="true" Filter="Contains"
        Height="150" HighlightTemplatedItems="true"
        OnItemsRequested="RadComboBox1_ItemsRequested"
        Width="325px" ErrorMessage="Dato errato" IsCaseSensitive="True">
    </telerik:RadComboBox>

     

     

     

     

     

     



  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Nov 2012 Link to this post

    Hi,

    Try the following code to show a RadComboBox with 10 items at a time.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Width="250" Height="150"
         EmptyMessage="Select a Company" EnableLoadOnDemand="True" ShowMoreResultsBox="true"
         EnableVirtualScrolling="true" OnItemsRequested="RadComboBox1_ItemsRequested"
         label="Server-Side:">
    </telerik:RadComboBox>

    VB:
    Private Const ItemsPerRequest As Integer = 10
    Protected Sub RadComboBox2_ItemsRequested(sender As Object, e As RadComboBoxItemsRequestedEventArgs)
        Dim data As DataTable = GetData(e.Text)
     
        Dim itemOffset As Integer = e.NumberOfItems
        Dim endOffset As Integer = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count)
        e.EndOfItems = endOffset = data.Rows.Count
     
        For i As Integer = itemOffset To endOffset - 1
            RadComboBox2.Items.Add(New RadComboBoxItem(data.Rows(i)("CompanyName").ToString(), data.Rows(i)("CompanyName").ToString()))
        Next
     
        e.Message = GetStatusMessage(endOffset, data.Rows.Count)
    End Sub
    Private Shared Function GetData(text As String) As DataTable
        Dim adapter As New SqlDataAdapter("SELECT * from Customers WHERE CompanyName LIKE @text + '%'", ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)
        adapter.SelectCommand.Parameters.AddWithValue("@text", text)
     
        Dim data As New DataTable()
        adapter.Fill(data)
     
        Return data
    End Function
    Private Shared Function GetStatusMessage(offset As Integer, total As Integer) As String
        If total <= 0 Then
            Return "No matches"
        End If
     
        Return [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total)
    End Function

    Hope this helps.

    Thanks,
    Princy.
  3. Fabio Cirillo
    Fabio Cirillo avatar
    181 posts
    Member since:
    Jan 2010

    Posted 15 Nov 2012 Link to this post

    thanks
    another question if I may, when I open the radcombobox if the records are to be loaded many would like to come out a waiting message like "wait or loading" ... if you use the property LoadingMessage, the message appears only when I'm writing the search key instead I want to appear when you load the entire list, you can do it?
  4. Fabio Cirillo
    Fabio Cirillo avatar
    181 posts
    Member since:
    Jan 2010

    Posted 16 Nov 2012 Link to this post

    Hello,

    I tried your code but when playing 10 records and then I will continue to display the next 10 and so on, does not work, I'll send you my code:

    <telerik:RadComboBox ID="Categoria" runat="server" Width="250" Height="150"
     
    EmptyMessage="Select a Company" EnableLoadOnDemand="True" ShowMoreResultsBox="true"
     
    EnableVirtualScrolling="true" OnItemsRequested="Categoria_ItemsRequested"
     
    label="Server-Side:">

    Private Const ItemsCategorie As Integer = 10
     
       Protected Sub Categoria_ItemsRequested(sender As Object, e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles Categoria.ItemsRequested
           Dim data As DataTable = GetDataCategoria(e.Text)
     
           Dim itemOffset As Integer = e.NumberOfItems
     
           Dim endOffset As Integer = Math.Min(itemOffset + ItemsCategorie, data.Rows.Count)
     
           e.EndOfItems = endOffset = data.Rows.Count
     
     
     
           For i As Integer = itemOffset To endOffset - 1
     
               Categoria.Items.Add(New RadComboBoxItem(data.Rows(i)("descrizione").ToString(), data.Rows(i)("id").ToString()))
     
           Next
     
     
     
           e.Message = GetStatusMessageCategoria(endOffset, data.Rows.Count)
     
       End Sub
       Private Shared Function GetDataCategoria(text As String) As DataTable
     
           Dim sqlSelectCommand As String = "SELECT [id], [descrizione] from [tab_categorie] WHERE [descrizione] LIKE @desc + '%' Order By [descrizione]"
     
           Dim adapter As New SqlDataAdapter(sqlSelectCommand, ConfigurationManager.ConnectionStrings("TrycontactString").ConnectionString)
           adapter.SelectCommand.Parameters.AddWithValue("@desc", text)
     
           Dim data As New DataTable()
     
           adapter.Fill(data)
     
           Return data
     
       End Function
     
       Private Shared Function GetStatusMessageCategoria(offset As Integer, total As Integer) As String
     
           If total <= 0 Then
     
               Return "No records"
     
           End If
     
           Return [String].Format("Items: <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total)
     
       End Function
  5. Nencho
    Admin
    Nencho avatar
    1871 posts

    Posted 20 Nov 2012 Link to this post

    Hi Fabio,

    I have prepared a sample project for you to demonstrate how you could implement an initial Loading Message. In addition, I have prepared the sample, based on the provided snippet of code, in order to show 10 items per request. Please find it attached.


    Regards,
    Nencho
    the Telerik team
    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 their blog feed now.
  6. Fabio Cirillo
    Fabio Cirillo avatar
    181 posts
    Member since:
    Jan 2010

    Posted 23 Nov 2012 Link to this post

    Thanks for your help,
    I tried using your code and it works but there is a small problem. When I open the radcombox you see the label Loading ... as your code but I radcombox set in the properties of the voice LoadingMessage = Loading. So when I do a search in the two words you see radcombox loading ... one imposed by your java function and the set from the property of the combo.
    How can I solve this problem?

    html code:
    <script type="text/javascript">
        function OnClientItemsRequesting(sender, eventArgs) {
            $telerik.$("#" + sender.get_id() + "_DropDown").find(".rcbScroll").prepend("<div id=\"RadComboBox1_LoadingDiv\" class=\"rcbLoading\">Loading...</div>")
        }
        function OnClientItemsRequested(sender, eventArgs) {
            $telerik.$("#" + sender.get_id() + "_DropDown").find(".rcbLoading").remove();
        }
    </script>
     
                                <telerik:RadComboBox ID="Region" Runat="server" CollapseDelay="100"
                                    EnableLoadOnDemand="True" HighlightTemplatedItems="True" IsCaseSensitive="True"
                                    LoadingMessage="Loading..." DropDownWidth="160px" Filter="StartsWith" Width="160px"
                                    MaxHeight="175px" ShowMoreResultsBox="True" Height="175px" OnClientItemsRequesting="OnClientItemsRequesting"
                                    AutoPostBack="True" OnSelectedIndexChanged="Region_SelectedIndexChanged" OnClientItemsRequested="OnClientItemsRequested" 
                                    EmptyMessage="Select region">
                                </telerik:RadComboBox>

    bye
  7. Nencho
    Admin
    Nencho avatar
    1871 posts

    Posted 28 Nov 2012 Link to this post

    Hello Fabio,

    I can suggest you to append the LoadingMessage, only if the ItemsRequested if fired for the first time. You could implement this approach using a flag in a following manner:

    <script type="text/javascript">
            var initialLoad = true;
     
            function OnClientItemsRequesting(sender, eventArgs) {
                if (initialLoad) {
     
                    $telerik.$("#" + sender.get_id() + "_DropDown").find(".rcbScroll").prepend("<div id=\"RadComboBox1_LoadingDiv\" class=\"rcbLoading\">Loading...</div>")
                }
            }
            function OnClientItemsRequested(sender, eventArgs) {
                if (initialLoad) {
                    $telerik.$("#" + sender.get_id() + "_DropDown").find(".rcbLoading").remove();
                    initialLoad = false;
                }
            }
     
        </script>



    Regards,
    Nencho
    the Telerik team
    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 their blog feed now.
Back to Top