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

Selection out of range Excpetion

9 Answers 1081 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 18 Jun 2009, 05:47 AM
Hello

I hv give the exception run time

Server Error in '/GowanKB' Application.

Selection out of range
Parameter name: value

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Selection out of range
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Selection out of range
Parameter name: value]
Telerik.Web.UI.RadComboBox.PerformDataBinding(IEnumerable dataSource) +180
Telerik.Web.UI.RadComboBox.OnDataSourceViewSelectCallback(IEnumerable data) +39
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e) +114
Telerik.Web.UI.RadComboBox.PerformSelect() +37
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +22
Telerik.Web.UI.RadDataBoundControl.OnPreRender(EventArgs e) +36
Telerik.Web.UI.RadComboBox.OnPreRender(EventArgs e) +42
System.Web.UI.Control.PreRenderRecursiveInternal() +80
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842


Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053


why this come

my querty is
SELECT DisplayName + ' ' + CoopOrg AS Name, Email FROM dbo.Coop
i can create the dummy column Name by using 2 different column it working sucessfully


and combobox property are

<telerik:RadComboBox ID="radcoopname" runat="server" Width="310" AppendDataBoundItems="true"
                                MarkFirstMatch="true" AutoPostBack="true" DataSourceID="coopname" DataTextField="Name"
                                DataValueField="Email" ExpandAnimation-Type="InQuart" CollapseAnimation-Duration="200"
                                CollapseAnimation-Type="Linear" CollapseDelay="400" CausesValidation="True">
                                <Items>
                                    <telerik:RadComboBoxItem Text="Select Coop Name" />
                                </Items>
                            </telerik:RadComboBox>


and code behind

 radcoopname.SelectedValue = (Session("CoOpDetail")).ToString

i need to select the session value when the combox load 
how i do this help me urgentttt

Can you please tell me where is the problem why this exception occure



9 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 18 Jun 2009, 07:33 AM
Hello rahul,

Please call the ClearSelection() method before data binding (DataBind()) the ComboBox.

Best wishes,
Simon
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
0
Justin
Top achievements
Rank 1
answered on 10 Mar 2011, 08:35 AM
Thank you Simon! It worked like a charm!
0
KJRB
Top achievements
Rank 1
answered on 28 Apr 2011, 09:33 PM
This is actually something that I had to add to the code after upgrading to 2011 Q1 from 2010 Q2.

 

 This worked before:

rcbCustomerCategory.DataSource = GetViewableCustomerCategories();
rcbCustomerCategory.DataTextField = "Name";
rcbCustomerCategory.DataValueField = "Id";
rcbCustomerCategory.DataBind();
rcbCustomerCategory.Items.Insert(0, new RadComboBoxItem("", "0"));

 

Now it needs to be:

 

 

 

rcbCustomerCategory.ClearSelection();
rcbCustomerCategory.DataSource = GetViewableCustomerCategories();
rcbCustomerCategory.DataTextField = "Name";
rcbCustomerCategory.DataValueField = "Id";
rcbCustomerCategory.DataBind();
rcbCustomerCategory.Items.Insert(0, new RadComboBoxItem("", "0"));

 

So, this is probbaly a breaking chanage in 2010 Q3 and 2011 Q1.

The code was rebinding the same control. But worked with 2010 Q2 broke after an upgrade.

 

 

 

 

 

0
Simon
Telerik team
answered on 02 May 2011, 02:47 PM
Hi KJRB,

We have not made any changes in regards to this functionality. What is more the exception has been in RadComboBox since its creation, so not having the exception is curious.

Is this all the code related to the RadComboBox? How did you submit the page when the exception occurred? Can you provide me with a minimum markup and code that are enough to reproduce the problem on a clean page?

All the best,
Simon
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
KJRB
Top achievements
Rank 1
answered on 04 May 2011, 04:39 AM

This is the demo page. The important things to notice are:

1) ViewState is disabled on the page
2) When you hit submit the page either crashes or is ok depending on things mentioned below:
    a) The code works fine if 2010 Q2 .NET 4.0 controls are referenced
    b)The code crashes if 2011 Q1 .NET 4.0 controls are referenced (I upgraded in order to fix IE9 issues)
    c) adding the commented line "//rcbCustomerCategory.ClearSelection();  " fixes the problem for 2011 Q1 controls.

I was aware of this issue with older controls. There were cases that I had to add "ClearSelection" but in most stituation I had no issue. This example code worked (for a long time) before it started experiencing problems (after an upgrade to 2011 Q1).
Also, this is just one example. I got this error in few places (probably all similar, not exact - some combos were populated via a web service for example).

This is the markup:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DefaultPage.aspx.cs" Inherits="RadComboClearItems.DefaultPage" EnableViewState="false" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
    <div>
    <telerik:RadComboBox 
                    ID="rcbCustomerCategory" 
                    Runat="server"
                    EmptyMessage="Select Customer Type" 
                    MarkFirstMatch="true"
                    AllowCustomText="false" 
                    EnableTextSelection="false"
                    Width="220" 
                    Height="140" /> <asp:Button runat="server" ID="btnSubmitt" Text="Submit" />
    </div>
    </form>
</body>
</html>


This is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
  
namespace RadComboClearItems
{
    public partial class DefaultPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //rcbCustomerCategory.ClearSelection();
            rcbCustomerCategory.DataSource = GetViewableCustomerCategories();
            rcbCustomerCategory.DataTextField = "Name";
            rcbCustomerCategory.DataValueField = "Id";
            rcbCustomerCategory.DataBind();
            rcbCustomerCategory.Items.Insert(0, new RadComboBoxItem("", "0"));
        }
  
        private static List<Category> GetViewableCustomerCategories()
        {
            return new List<Category> { new Category { Id = 1, Name = "Categ 1" }, new Category { Id = 2, Name = "Categ 2" } };
        }
  
  
    }
  
    public class Category
    {
        public string Name { get; set; }
        public int Id { get; set; }
    }
}



This is the error message:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Selection out of range
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Selection out of range
Parameter name: value

Source Error:

Line 17: rcbCustomerCategory.DataTextField = "Name";
Line 18: rcbCustomerCategory.DataValueField = "Id";
Line 19: rcbCustomerCategory.DataBind();
Line 20: rcbCustomerCategory.Items.Insert(0, new RadComboBoxItem("", "0"));
Line 21: }

Source File: C:\Projects\KJRB\Experiments\RadComboClearItems\DefaultPage.aspx.cs Line: 19

Stack Trace:

[ArgumentOutOfRangeException: Selection out of range
Parameter name: value]
Telerik.Web.UI.RadComboBox.PerformDataBinding(IEnumerable dataSource) +299
Telerik.Web.UI.RadComboBox.OnDataSourceViewSelectCallback(IEnumerable data) +299
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e) +661
Telerik.Web.UI.RadComboBox.PerformSelect() +21
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
Telerik.Web.UI.RadComboBox.DataBind() +38
RadComboClearItems.DefaultPage.Page_Load(Object sender, EventArgs e) in C:\Projects\KJRB\Experiments\RadComboClearItems\DefaultPage.aspx.cs:19
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

0
Simon
Telerik team
answered on 11 May 2011, 05:05 PM
Hello KJRB,

Thank you for the code and the instructions.

Indeed the exception is not present in the Q2 2010 release, however, it should have been there. Probably some other bug, which we have resolved after that, is preventing the exception for some reason.

So, the exception is thrown when the new data source does not contain the previously selected value. In your case, the first Item is selected (with value '0') on the first page load. If the page is posted back without any changes to the selection of the RadComboBox, after calling DataBind, the first Item (with value '0') will not exist in the data source, hence the exception will be thrown.

Another way of avoiding the error, in addition to calling ClearSelection is the following:
  protected void Page_Load(object sender, EventArgs e)
 {
     //rcbCustomerCategory.ClearSelection();
     rcbCustomerCategory.DataSource = GetViewableCustomerCategories(Page.IsPostBack);
     rcbCustomerCategory.DataTextField = "Name";
     rcbCustomerCategory.DataValueField = "Id";
     rcbCustomerCategory.Items.Insert(0, new RadComboBoxItem("", "0"));
     rcbCustomerCategory.AppendDataBoundItems = true;
     rcbCustomerCategory.DataBind();
 }

I hope this helps.

Greetings,
Simon
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
KJRB
Top achievements
Rank 1
answered on 11 May 2011, 06:07 PM
Thanks Simon for the explanation why the error occurs and for showing the other option for fixing it.
Appreciate it.
0
Berry Kropiwka
Top achievements
Rank 1
answered on 12 May 2011, 01:38 PM
Hi Simon
We also have this issue with 2011 Q1.
We've been using the controls Sept of 2009.
This breaks cascading comboboxes.
The example would be a make and model for cars.

Not sure i understand why the correct behaviour after a databind is an error
if the old selection is missing from the new data.

If the fix is to put a ClearSelection before the databind what condition would
exist if i don't have to put ClearSelection.


In our case we have to review 287 databinds in 47 files. Not really looking forward
to that.

Should i open a ticket?

Thanks
0
Simon
Telerik team
answered on 23 May 2011, 09:27 AM
Hi Berry Kropiwka,

Let me first briefly introduce you to the origins of the exception. The reason for its existence is that it also is thrown by the standard ASP.NET DropDownList control in exactly the same setup. When RadComboBox for ASP.NET AJAX was built the main design goal of the developers was to make it a 100% substitute for the DropDownList, so they mimicked not only the latter's benefits but also its peculiarities. This exception is one such peculiarity.

Now, you are perfectly right: "In our case we have to review 287 databinds in 47 files. Not really looking forward to that." Additionally there seems to be no valid reason for this exception to be thrown when, for instance, the selection could simply reset in the given case.

Since this issue is generating a lot of frustration we will consider getting rid of the exception or provide a more meaningful exception message.

All the best,
Simon
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
ComboBox
Asked by
Rahul
Top achievements
Rank 1
Answers by
Simon
Telerik team
Justin
Top achievements
Rank 1
KJRB
Top achievements
Rank 1
Berry Kropiwka
Top achievements
Rank 1
Share this question
or