LoadOnDemand Position

6 posts, 0 answers
  1. jprian
    jprian avatar
    43 posts
    Member since:
    Sep 2006

    Posted 17 Jan 2013 Link to this post

    Hi,
    we are using radcombobox with LoadOnDemand. Everything works ok except the positioning of the item when we click on MoreResults. Items are loading correctly but the list of items in dropdownbox is positioned back in the first item again and not in the new first loaded item, that is, we see the first item if I scroll to the last item and then I click on MoreResults option; then new items are loaded but we see item(0) again and not item(10) if ItemsPerRequest is set to 10. In demo ComboBox / Load on Demand Modes (http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultvb.aspx ) it works fine.
    Our radcombobox control is defined:

    <Telerik:RadCombobox ID="ddl_radcombo" runat="server" AllowCustomText="false" AutoPostBack="true"  EnableLoadOnDemand="true" Filter="none" Height="100px" LoadingMessage="..." MarkFirstMatch="false" ShowMoreResultsBox="true" Width="95%">
    </Telerik:RadCombobox>

    Please, any cue?, any idea?

    Thanks in advance.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Jan 2013 Link to this post

    Hi,

    I suppose you are missing the server-side logic in the ItemsRequested event handler that loads only the needed portion of Items.

    C#:
    protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        string sql = "SELECT * from Customers WHERE CompanyName LIKE '" + e.Text + "%'";
        SqlDataAdapter adapter = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
        DataTable data = new DataTable();
        adapter.Fill(data);
        //loads only the needed portion of Items
        try
        {
            int itemsPerRequest = 10;
            int itemOffset = e.NumberOfItems;
            int endOffset = itemOffset + itemsPerRequest;
            if (endOffset > data.Rows.Count)
            {
                endOffset = data.Rows.Count;
            }
            for (int i = itemOffset; i < endOffset; i++)
            {
                RadComboBox1.Items.Add(new RadComboBoxItem(data.Rows[i]["CompanyName"].ToString(), data.Rows[i]["CompanyName"].ToString() + "'"));
            }
            if (data.Rows.Count > 0)
            {
                e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString());
            }
            else { e.Message = "No matches"; }
        }
        catch
        {
            e.Message = "No matches";
        }
    }

    Please take a look into this documentation and demo for the complete code.

    Please provide your full code if doesn't helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. jprian
    jprian avatar
    43 posts
    Member since:
    Sep 2006

    Posted 21 Jan 2013 Link to this post

    Hi Princy,
    thanks for your interest.
    We are setting ItemsPerRequest to 10, so we are loading 10 by 10 blocks of items. In other words, first time we load items from 0 to 9, when user click in MoreResults area, we are loading items from 10 to 19 and so on. This is works ok but item list is not showing item 10 when first time user click on MoreResults, it is showing item 0 again although user scrolls list item to last item.

    Thanks again
    Best Regards
  5. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 21 Jan 2013 Link to this post

    Hello jprian,

    Have you tried setting EnableVirtualScrolling="true" on your RadComboBox.

    I hope that helps.
  6. jprian
    jprian avatar
    43 posts
    Member since:
    Sep 2006

    Posted 23 Jan 2013 Link to this post

    Hi Kevin thanks four your tip,
    i've tried setting EnableVirtualScrolling="true", but behaviour is the same, load data but showed position is first again each time next items are loaded.

    Perhaps the problem is loading data, this is the code to load data:
    Protected Sub ddl_combo_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles ddl_combo.ItemsRequested
        Dim mensaje As String = String.Empty
        Cargar_ddlActivosOnDemand(e.NumberOfItems, 10, conexion, mensaje, ddl_combo, e.Text)
        e.Message = mensaje
    End Sub
     
     
    Function Cargar_ddlActivosOnDemand(ByVal ItemOffset As Integer, _
        ByVal ItemsPerRequest As Integer, _
        ByVal Cnx As OleDbConnection, _
        ByRef Mensaje As String, _
        ByVal ctrl_dropdown As Telerik.Web.UI.RadComboBox, _
        Optional ByVal TextoFiltro As String = "") As Boolean
     
        Dim strsql As String
        Dim data As System.Data.DataTable
        strsql = "SELECT *  FROM TABLA WHERE  (DESCFIELD LIKE '%" & TextoFiltro.Trim.Replace("'", "''") & "%')"
     
        data = Ejecutar_Consulta_DataSet(Cnx, strsql).Tables(0)'Return Table
     
        Dim endOffset As Integer = Math.Min(ItemOffset + ItemsPerRequest, data.Rows.Count)
        For i As Integer = ItemOffset To endOffset - 1
            Dim ItemCombo As New Telerik.Web.UI.RadComboBoxItem()
            With ItemCombo
                .Value = data.Rows(i)("CODFIELD").ToString()
                .Text = data.Rows(i)("DESCFIELD").ToString() & "(" & data.Rows(i)("CODFIELD").ToString() & ")"
                ctrl_dropdown.Items.Add(ItemCombo)
            End With
        Next i
        Mensaje = endOffset & " - " & data.Rows.Count
        Return True
    End Function

    Thanks to everybody

    JPrian
  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 28 Jan 2013 Link to this post

    Hello,

    Please find attached a sample project that demonstrates RadComboBox LoadOnDemant functionality with virtual scrolling property set to true. I would recommend modifying this project with your database queries and data in order to avoid that unusual behavior.

    Regards,
    Boyan Dimitrov
    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
UI for ASP.NET Ajax is Ready for VS 2017