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

LoadOnDemand Position

5 Answers 88 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
jprian
Top achievements
Rank 1
jprian asked on 17 Jan 2013, 07:10 PM
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.

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Jan 2013, 04:42 AM
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.
0
jprian
Top achievements
Rank 1
answered on 21 Jan 2013, 08:50 AM
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
0
Kevin
Top achievements
Rank 2
answered on 21 Jan 2013, 03:24 PM
Hello jprian,

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

I hope that helps.
0
jprian
Top achievements
Rank 1
answered on 23 Jan 2013, 02:47 PM
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
0
Boyan Dimitrov
Telerik team
answered on 28 Jan 2013, 12:35 PM
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.
Tags
ComboBox
Asked by
jprian
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
jprian
Top achievements
Rank 1
Kevin
Top achievements
Rank 2
Boyan Dimitrov
Telerik team
Share this question
or