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

[Solved] Selection out of range on Combo when used with radAjaxPanel

1 Answer 168 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ric Pullen
Top achievements
Rank 1
Ric Pullen asked on 24 Jun 2008, 07:45 AM
I have searched the forum but have not found a related response to the issue I am reciving.

I have a large collection of address that a user might want to add to an editor so I have created an on demand drop down list, and a button (which when clicked inserts the value into the editor)

This all works but does a full postback so I positioned the combo (both inside and outside) the ajaxPanel along with the button and the editor   On clicking the button, the address is added correctly, on a subsequent search I get the Selection out of Range: Parameter Name Value.

 <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server"   
        height="75px" InitialDelayTime="500" Transparency="25" width="75px">  
        <img alt="Loading..."   
            src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>'   
            style="border:0px;" /> 
    </telerik:RadAjaxLoadingPanel><telerik:RadComboBox ID="rcmbGlobalAddress"   
            runat="server" AllowCustomText="True" CausesValidation="False"   
            EnableLoadOnDemand="True" Height="140px" ShowDropDownOnTextboxClick="False"   
            Skin="Outlook" SkinsPath="~/RadControls/ComboBox/Skins" Width="292px">  
            <CollapseAnimation Duration="200" Type="OutQuint" /> 
        </telerik:RadComboBox> 
    <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" height="200px"   
        HorizontalAlign="NotSet" LoadingPanelID="RadAjaxLoadingPanel1" width="100%">  
        &nbsp;<asp:Button ID="btnAddcc" runat="server" Height="25px" Text="Add CC:" /> 
        <telerik:RadEditor ID="RadEditor2" Runat="server" EditModes="Design"   
            Font-Names="Arial" Font-Size="12pt" Skin="Outlook"   
            StripFormattingOptions="MSWordRemoveAll" Width="735px">  
            <Tools> 
                <telerik:EditorToolGroup Tag="Empty">  
                    <telerik:EditorTool Name="AboutDialog" /> 
                </telerik:EditorToolGroup> 
            </Tools> 
            <Content> 
</Content> 
        </telerik:RadEditor> 
    </telerik:RadAjaxPanel> 

Code behind:
  Protected Sub rcmbGlobalAddress_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles rcmbGlobalAddress.ItemsRequested  
        If e.Text = String.Empty Then Exit Sub 
        Dim dl As New Datalogic  
        dtGlobalAddress = dl.getGlobalAddress(e.Text)  
 
        With rcmbGlobalAddress  
            .DataSource = dtGlobalAddress  
            .DataValueField = dtGlobalAddress.Columns(1).ColumnName  
            .DataTextField = dtGlobalAddress.Columns(0).ColumnName  
            .DataBind()  
        End With 
    End Sub 
The error on the server is trapped on the databind: and I have checked that rows are being correctly been returned from the following snippet.

Public Function getGlobalAddress(ByVal filterval As String) As DataTable  
        _Command = New SqlCommand  
        _DataResults = New DataSet  
        With _Command  
            .CommandText = "usp_SelectGlobalAddresses" 
            .CommandType = CommandType.StoredProcedure  
            .Connection = _Connection  
            .Parameters.Add("@StartsWith", SqlDbType.VarChar, 99)  
            .Parameters("@StartsWith").Value = filterval  
        End With 
        Try 
            _Connection.Open()  
            _DataAdapter = New SqlDataAdapter(_Command)  
            _DataAdapter.Fill(_DataResults)  
            Return _DataResults.Tables(0)  
        Catch ex As Exception  
            _Error = ex.Message  
            getGlobalAddress = Nothing 
            ' Throw ex  
        Finally 
            _Connection.Close()  
        End Try 
    End Function 


1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 26 Jun 2008, 02:56 PM
Hello Ric Pullen,

Please try clearing the selection of the ComboBox right before binding it like this:

    Protected Sub rcmbGlobalAddress_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles rcmbGlobalAddress.ItemsRequested   
        If e.Text = String.Empty Then Exit Sub  
        Dim dl As New Datalogic   
        dtGlobalAddress = dl.getGlobalAddress(e.Text)   
  
        With rcmbGlobalAddress 
            .ClearSelection()   
            .DataSource = dtGlobalAddress   
            .DataValueField = dtGlobalAddress.Columns(1).ColumnName   
            .DataTextField = dtGlobalAddress.Columns(0).ColumnName   
            .DataBind()   
        End With  
    End Sub  

When you select an Item for the first time, the ComboBox 'remembers' the value of this Item. When you subsequently re-bind the control (presumably with new Items) it tries to re-select the previously selected Item by value. Since the Item does not exist any more in the list of Items, an exception is thrown.

Sincerely yours,
Simon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Ric Pullen
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or