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

ComboBox and EmptyMessage

1 Answer 116 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 26 Mar 2009, 06:23 PM
I'm using a radcombobox to populate items  from a database on demand.  All works well except for when EmptyMessage is set

The Problem:

    On the first attempt to drop the box down, it displays no matches and nothing comes up in the list.  The second dropdown attempt everything works perfectly.  Happens only when the EmptyMessage property is set.  I'm stumped.

----
Here is what my code looks like:

.aspx and javascript

<telerik:RadComboBox ID="cboCities" runat="server" AutoPostBack="True" EnableLoadOnDemand="True"   
                                                            EnableVirtualScrolling="True" Height="200px" MarkFirstMatch="True"   
                                                            OnClientItemsRequesting="OnClientItemsRequesting"   
                                                            OnItemsRequested="cboCities_ItemsRequested" Filter="None" ShowMoreResultsBox="True"   
                                                            Width="240px" Font-Size="X-Small" AllowCustomText="True"   
                                                            EmptyMessage="Type a city name" Skin="Black">  
                                                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                                        </telerik:RadComboBox> 


function OnClientItemsRequesting(sender,e)  
{  
    if(sender.get_appendItems())  
        e.get_context().CustomText="";  
    else 
        e.get_context().CustomText=sender.get_text();  

Finally the codebehind:

Protected Sub cboCities_ItemsRequested(ByVal sender As ObjectByVal e As RadComboBoxItemsRequestedEventArgs)  
 
        Dim sql As String = "Select cityCode,cityName,State,Lat,Long from s_CityMaster WHERE Cityname LIKE '%" + e.Context("CustomText").ToString() + "%' ORDER BY CityName" 
 
        Dim adapter As New SqlDataAdapter(sql, ConfigurationManager.AppSettings("BioDiasporaCS"))  
        Dim data As New DataTable()  
        adapter.Fill(data)  
 
        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  
                cboCities.Items.Add(New RadComboBoxItem(data.Rows(i)("cityName").ToString(), data.Rows(i)("cityName").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 

Can anyone help me with what I'm doing wrong? Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 31 Mar 2009, 07:57 AM
Hello Michael,

Thank you for raising the issue.

This is a bug which we are aware of and will fix with the upcoming Service Pack which is due to the end of this week.

Kind regards,
Simon
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Michael
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or