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

[Solved] LoadOnDemand Not Finding Items in List

1 Answer 178 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Bob Gibilaro
Top achievements
Rank 1
Bob Gibilaro asked on 23 Jun 2008, 08:17 PM

Hi, I'm using RadComboBox ("RadControls for ASPNET AJAX Q1 2008") with load on demand.  I seem to have it half-working.  It will successfully display "1-10 of 8836", and when I type in the first few letters of any of the first ten items in the list it will successfully highlight that item which matches.  The problem is that when I type in letters which should match items which are not in the first ten it will not find it; it will say "Loading..." for a few seconds but then "Loading..." will disappear and no items will be selected even though I have confirmed that what I'm searching for should be in the list based on what I'm seeing in the database.

My code is below, most of which I copied from your website:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/ComboBox/Examples/PopulatingWithData/AutoCompleteSql/DefaultVB.aspx

<asp:GridView Width=100% ID="gvLines" runat=server AutoGenerateColumns=false>
<HeaderStyle CssClass=dgheader/>
<RowStyle CssClass=dgrows />
<Alternatingrowstyle CssClass=dgalternating />
<Columns>
<asp:TemplateField HeaderText="Customer">
<ItemTemplate>
    <telerik:RadComboBox
        ID="RadComboBox1" runat="server" Width="250px" Height="200px"
                AllowCustomText="True" ShowToggleImage="True" ShowMoreResultsBox="true"
                    EnableLoadOnDemand="True" MarkFirstMatch="True" OnItemsRequested="RadComboBox1_ItemsRequested" EnableVirtualScrolling="true">
    </telerik:RadComboBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

-------------------------------------

Protected Sub RadComboBox1_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)

Dim sql As String = "SELECT CUSTOMER = RTRIM(CUST_NO) + ' - ' + CUST_NAME from DATA_POOL.DBO.Customer (NOLOCK) "

Dim adapter As New SqlDataAdapter(sql, conn)
Dim data As New DataTable()
adapter.Fill(data)

Dim rcb As RadComboBox = CType(o, RadComboBox)

Try

    Dim itemsPerRequest As Integer = 10
    Dim itemOffset As Integer = e.NumberOfItems
    Dim endOffset As Integer = itemOffset + itemsPerRequest
    If endOffset > data.Rows.Count Then
        endOffset = data.Rows.Count
    End If

    If endOffset = data.Rows.Count Then
        e.EndOfItems = True
    End If
    Dim i As Integer = itemOffset
    While i < endOffset
        rcb.Items.Add(New RadComboBoxItem(data.Rows(i)("CUSTOMER").ToString(), data.Rows(i)("CUSTOMER").ToString()))
        i = i + 1
    End While

    If data.Rows.Count > 0 Then
        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"
    End If
Catch
    e.Message = "No matches"
End Try

End Sub

1 Answer, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 26 Jun 2008, 12:57 PM
Hello Bob Gibilaro,

This is the correct behavior because:

You load all items from the database (you do not have a where clause in the SQL query), but you show only the first 10 of them. Typing some text will activate the MarkFirstMatch functionality which will search in these 10 records for a match - if it is not found - the text will be reset to an empty string.

What you need to do is to put a "where" clause in your sql query, for example:

Dim sql As String = "SELECT CUSTOMER = RTRIM(CUST_NO) + ' - ' + CUST_NAME from DATA_POOL.DBO.Customer WHERE CUST_NAME like '" + e.Text + "%'";

In this way when you type something in the combo - the first 10 results from the database starting with that text will be returned and added as combo items, then the MarkFirstMatch mechanism will work over these items.

I hope this helps.

Best wishes,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Bob Gibilaro
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or