ComboBox Not Clearing initial page load data when show more results is selected.

2 posts, 0 answers
  1. Ryan
    Ryan avatar
    4 posts
    Member since:
    Jan 2013

    Posted 03 Jan 2013 Link to this post



    On page load i bind data to the combobox control but if the user selects the ShowMoreResults arrow
     down button 
    to load more items(even though i display all items) it appends the same amount of items
     to the box without clearing the original binded items. even though when the rcboSearch_ItemsRequested is launched it is set to clear the combobox and
    indeed stepping through the code it says it has the output on screen is that
    the page load data is mixed with the new data.


    note if the user starts to type into the combobox the results get cleared.
    the problem is only when i append data on page load and select ShowMoreResults
    arrow which seems to be present even though 
    there shouldnt be any more results to load,
     this triggers 
    rcboSearch_ItemsRequested and adds the same amount of data
     as page load to the data already there







    <telerik:RadComboBox runat="server" ID="ComboAllContacts"  Width="300"
                    ShowMoreResultsBox="true" MaxLength="250" EnableVirtualScrolling="true" EnableLoadOnDemand="true"
                    EmptyMessage="Select Area" MarkFirstMatch="false" AllowCustomText="false" HighlightTemplatedItems="false"
                    EnableItemCaching="false" MinFilterLength="1" CssClass="fx-areaselector"  OnItemsRequested="rcboSearch_ItemsRequested"
                    skin="Fluent" EnableEmbeddedSkins="false" DataValueField="CRMAreaID" ClientIDMode="Static" >
     
         <ItemTemplate>
               <div class="searchResult">
               <div class="profilePicContainer">
              <a  title="View <%# DataBinder.Eval(Container, "Attributes['Name']")%>"><%# DataBinder.Eval(Container,        "Attributes['Name']")%></a>  
             </div>
             </div>
               <div class="separatorTemplate" style="display: none;">
                <h2><%#DataBinder.Eval(Container, "Attributes['Name']")%></h2>
               </div>
           </ItemTemplate>
    </telerik:RadComboBox>



    <<< Page Load >>>

    If Not IsPostBack Then
                Dim currentRowType = String.Empty
     
                Dim ds As DataSet = AreaHelper.GetMyAreas()
                Dim dt As DataTable = ds.Tables(0)
     
     
                ComboAllContacts.DataValueField = "CRMAreaID"
     
                For Each row As DataRow In dt.Rows
     
                    Dim item As New RadComboBoxItem
                    Dim CRMAreaID As String = row("CRMAreaID").ToString()
                    Dim Name As String = row("Name").ToString()
                    Dim Region As String = row("Region").ToString()
     
                    If currentRowType <> Region Then
                        ' Add separator Row
                        ComboAllContacts.Items.Add(CreateSeparatorItem(Region))
                        currentRowType = Region
                    End If
     
     
                    item.Value = CRMAreaID.ToString()
                    item.Text = Name
     
                    item.Attributes.Add("CRMAreaID", CRMAreaID)
                    item.Attributes.Add("Region", Region)
                    item.Attributes.Add("Name", Name)
                    item.Attributes.Add("IsSeparator", False)
                    item.Attributes.Add("onclick", "NavigateAreaSelection(" + CRMAreaID + ")")
     
                    If Not String.IsNullOrWhiteSpace(item.Text) Then
                        ComboAllContacts.Items.Add(item)
                    End If
                Next row
     
     
                ComboAllContacts.DataBind()
     
            End If



    <<<ItemsRequested>>>

    Protected Sub Protected Sub rcboSearch_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
     
            '' RadComboBox combo = this.FindControl("combo") as RadComboBox;
            ComboAllContacts.ClearSelection()
            ComboAllContacts.Items.Clear()
            ComboAllContacts.Dispose()
            ComboAllContacts.Text = ""
     
     
     
     
            Dim data As DataTable = GetData(e.Text)
     
            Dim itemOffset As Integer = e.NumberOfItems
            Dim endOffset As Integer = data.Rows.Count ''Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count)
            e.EndOfItems = endOffset = data.Rows.Count
     
            'If data.Rows.Count > 0 Then
     
            'End If
     
            Dim currentRowType = String.Empty
     
     
            ''For i As Integer = itemOffset To endOffset - 1
            For Each row As DataRow In data.Rows
     
                Dim item As New RadComboBoxItem
                'Dim CRMAreaID As String = data.Rows(i)("RowID").ToString()
                'Dim rowName As String = data.Rows(i)("Name").ToString()
                'Dim Region As String = data.Rows(i)("Region").ToString()
     
                Dim CRMAreaID As String = row("RowID").ToString()
                Dim rowName As String = row("Name").ToString()
                Dim Region As String = row("Region").ToString()
     
                If currentRowType <> Region Then
                    ' Add separator Row
                    ComboAllContacts.Items.Add(CreateSeparatorItem(Region))
                    currentRowType = Region
                End If
     
     
                item.Value = CRMAreaID
                item.Text = rowName
     
                item.Attributes.Add("CRMAreaID", CRMAreaID)
                item.Attributes.Add("Region", Region)
                item.Attributes.Add("Name", rowName)
                item.Attributes.Add("IsSeparator", False)
                item.Attributes.Add("onclick", "NavigateAreaSelection(" + CRMAreaID + ")")
     
                If Not String.IsNullOrWhiteSpace(item.Text) Then
                    ComboAllContacts.Items.Add(item)
                End If
                ''Next row
            Next
     
     
     
            If ComboAllContacts.Items.Count > 0 Then
                ComboAllContacts.DataBind()
            Else
     
            End If
            e.Message = GetStatusMessage(endOffset, ComboAllContacts.Items.Count)(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
     
            '' RadComboBox combo = this.FindControl("combo") as RadComboBox;
            ComboAllContacts.ClearSelection()
            ComboAllContacts.Items.Clear()
            ComboAllContacts.Dispose()
            ComboAllContacts.Text = ""
     
     
     
     
            Dim data As DataTable = GetData(e.Text)
     
            Dim itemOffset As Integer = e.NumberOfItems
            Dim endOffset As Integer = data.Rows.Count ''Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count)
            e.EndOfItems = endOffset = data.Rows.Count
     
            'If data.Rows.Count > 0 Then
     
            'End If
     
            Dim currentRowType = String.Empty
     
     
            ''For i As Integer = itemOffset To endOffset - 1
            For Each row As DataRow In data.Rows
     
                Dim item As New RadComboBoxItem
                'Dim CRMAreaID As String = data.Rows(i)("RowID").ToString()
                'Dim rowName As String = data.Rows(i)("Name").ToString()
                'Dim Region As String = data.Rows(i)("Region").ToString()
     
                Dim CRMAreaID As String = row("RowID").ToString()
                Dim rowName As String = row("Name").ToString()
                Dim Region As String = row("Region").ToString()
     
                If currentRowType <> Region Then
                    ' Add separator Row
                    ComboAllContacts.Items.Add(CreateSeparatorItem(Region))
                    currentRowType = Region
                End If
     
     
                item.Value = CRMAreaID
                item.Text = rowName
     
                item.Attributes.Add("CRMAreaID", CRMAreaID)
                item.Attributes.Add("Region", Region)
                item.Attributes.Add("Name", rowName)
                item.Attributes.Add("IsSeparator", False)
                item.Attributes.Add("onclick", "NavigateAreaSelection(" + CRMAreaID + ")")
     
                If Not String.IsNullOrWhiteSpace(item.Text) Then
                    ComboAllContacts.Items.Add(item)
                End If
                ''Next row
            Next
     
     
     
            If ComboAllContacts.Items.Count > 0 Then
                ComboAllContacts.DataBind()
            Else
            End If
            e.Message = GetStatusMessage(endOffset, ComboAllContacts.Items.Count)



  2. Nencho
    Admin
    Nencho avatar
    1864 posts

    Posted 08 Jan 2013 Link to this post

    Hello Ryan,

    As I can see, you had comment out the itemOffset calculation, on which the correct behavior of the desired functionality rely. The itemOffset and endOffset are responsible for calculating the portion of items, which is about to be loaded in the RadComboBox. Please refer to our online demo, where this functionality is implemented.

    Greetings,
    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