Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > radcombobox bind errors on null entries
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered radcombobox bind errors on null entries

Feed from this thread
  • mark avatar

    Posted on Mar 14, 2008 (permalink)

    I'm using the radcombo bot to bind to a option field in my database.  the ID can be null and that's OK.  using classic ASP controlls, i'd set AppendDataboundItems to true and then define an item with value="" to be the null option.  this is the code:

    1 <radG:GridTemplateColumn DataField="InterviewConfigId" HeaderText="Interview Link" 
    2                     UniqueName="TemplateColumn"
    3                     <EditItemTemplate> 
    4                         <radcb:radcombobox id="RadComboBox1" runat="server" datasourceid="ObjectDataSourceInterview" 
    5                             selectedvalue='<%# Bind("Id") %>' skin="County" skinspath="~/RadControls/ComboBox/Skins" 
    6                             width="150px" AppendDataBoundItems="True" DataTextField="ShortName" DataValueField="Id"
    7                             <Items> 
    8                                 <radCb:RadComboBoxItem runat="server" Selected="True" Value="" Text="Pick an Interview Question" /> 
    9                             </Items> 
    10                         </radcb:radcombobox> 
    11                     </EditItemTemplate> 
    12                     <ItemTemplate> 
    13                         <asp:Label ID="Label1" runat="server" Text='<%# Eval("ShortName") %>'></asp:Label> 
    14                     </ItemTemplate> 
    15                 </radG:GridTemplateColumn> 


    when i run it on a row with a null ID, i get :

    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.WebControls.RadComboBox.PerformDataBinding(IEnumerable dataSource) +233
    Telerik.WebControls.RadComboBox.OnDataSourceViewSelectCallback(IEnumerable data) +31
    System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +29
    Telerik.WebControls.RadComboBox.OnDataBinding(EventArgs e) +102
    Telerik.WebControls.RadComboBox.PerformSelect() +32


  • Nick Nick admin's avatar

    Posted on Mar 17, 2008 (permalink)

    Hi mark,

    I tried to reproduce the problem at our end, but to no avail. Attached, please find a small and running project on the matter. Download it and give it a go.

    What am I missing?

    Regards,
    Nick
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
    Attached files

  • John avatar

    Posted on Jun 26, 2008 (permalink)

    Nick,

    I downloaded your project to look at it and you do not have the SelectedValue='<%# Bind("") %>' in you radcombobox.

    So this does not give a solution to the problem that Mark and myself have. If i don't bind the control in classic asp level my data will load into the control but, if we set the bind property i get the same error message. here is my code.

    <

    radG:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None" Width="616px">

    <MasterTableView AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"

    AutoGenerateColumns="False" CommandItemDisplay="Top" DataKeyNames="OrderID" DataSourceID="SqlDataSource1">

    <EditFormSettings EditFormType="Template">

    <FormTemplate>

    <radC:RadComboBox ID="RadComboBox1" SelectedValue='<%# Bind("EmployeeId") %>' runat="server">

    </radC:RadComboBox>

    </FormTemplate>

    </EditFormSettings>

    <Columns>

    <radG:GridEditCommandColumn>

    </radG:GridEditCommandColumn>

    <radG:GridBoundColumn DataField="OrderID" DataType="System.Int32" HeaderText="OrderID"

    ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="EmployeeID" DataType="System.Int32" HeaderText="EmployeeID"

    SortExpression="EmployeeID" UniqueName="EmployeeID">

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="OrderDate" DataType="System.DateTime" HeaderText="OrderDate"

    SortExpression="OrderDate" UniqueName="OrderDate">

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="RequiredDate" DataType="System.DateTime" HeaderText="RequiredDate"

    SortExpression="RequiredDate" UniqueName="RequiredDate">

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="ShippedDate" DataType="System.DateTime" HeaderText="ShippedDate"

    SortExpression="ShippedDate" UniqueName="ShippedDate">

    </radG:GridBoundColumn>

    </Columns>

    <ExpandCollapseColumn Visible="False">

    <HeaderStyle Width="19px" />

    </ExpandCollapseColumn>

    <RowIndicatorColumn Visible="False">

    <HeaderStyle Width="20px" />

    </RowIndicatorColumn>

    </MasterTableView>

    </radG:RadGrid><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NwindConnectionString %>"

    DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = ?" InsertCommand="INSERT INTO [Orders] ([OrderID], [EmployeeID], [OrderDate], [RequiredDate], [ShippedDate]) VALUES (?, ?, ?, ?, ?)"

    ProviderName="<%$ ConnectionStrings:NwindConnectionString.ProviderName %>" SelectCommand="SELECT [OrderID], [EmployeeID], [OrderDate], [RequiredDate], [ShippedDate] FROM [Orders]"

    UpdateCommand="UPDATE [Orders] SET [EmployeeID] = ?, [OrderDate] = ?, [RequiredDate] = ?, [ShippedDate] = ? WHERE [OrderID] = ?">

    <DeleteParameters>

    <asp:Parameter Name="OrderID" Type="Int32" />

    </DeleteParameters>

    <UpdateParameters>

    <asp:Parameter Name="EmployeeID" Type="Int32" />

    <asp:Parameter Name="OrderDate" Type="DateTime" />

    <asp:Parameter Name="RequiredDate" Type="DateTime" />

    <asp:Parameter Name="ShippedDate" Type="DateTime" />

    <asp:Parameter Name="OrderID" Type="Int32" />

    </UpdateParameters>

    <InsertParameters>

    <asp:Parameter Name="OrderID" Type="Int32" />

    <asp:Parameter Name="EmployeeID" Type="Int32" />

    <asp:Parameter Name="OrderDate" Type="DateTime" />

    <asp:Parameter Name="RequiredDate" Type="DateTime" />

    <asp:Parameter Name="ShippedDate" Type="DateTime" />

    </InsertParameters>

    </asp:SqlDataSource>

    </div>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NwindConnectionString %>"

    ProviderName="<%$ ConnectionStrings:NwindConnectionString.ProviderName %>"></asp:SqlDataSource>

    --------------------------------------------------------------------
    Private

    Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid1.ItemDataBound

    If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then

     

    Dim item As GridEditableItem = CType(e.Item, GridEditableItem)

    Dim list As RadComboBox = CType(item.FindControl("RadComboBox1"), RadComboBox)

    Me.SqlDataSource2.SelectCommand = "SELECT [EmployeeID], [LastName] FROM [Employees]"

    list.DataSourceID =

    "SqlDataSource2"

    list.DataTextField =

    "LastName"

    list.DataValueField =

    "EmployeeID"

    list.DataBind()

    'list.SelectedIndex = 0

    End If

    End Sub

  • Simon Simon admin's avatar

    Posted on Jun 30, 2008 (permalink)

    Hello John,

    The reason for this error is that the value you set as selected in the RadComboBox does not exist in the list of Items already loaded in the control.

    You need to ensure that, EmployeeId in your case, exists and can be actually selected in the ComboBox control.

    In case where the bound column allows NULL values as in Mark's case, the best way to avoid the error is to select empty strings instead of the NULLs or convert them to empty strings after the data is selected. Finally, an Item with value = String.Empty or "" should exist in the ComboBox.

    All the best,
    Simon
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • reverland avatar

    Posted on Sep 12, 2008 (permalink)

    I am having this issue as well, it didn't used to be like this. I am using it to load a list of states or provinces depending on the country. I found the only way to fix this was to set the selectedindex as 0, but this is something new that has popped up in the latest release.

  • Simon Simon admin's avatar

    Posted on Sep 15, 2008 (permalink)

    Hello reverland,

    I am not quite sure that the problem discussed so far in this thread is the same as yours. RadComboBox will throw the error as it is 'a default behavior', similarly to the classic DropDownList control.

    Could you open a formal support ticket and send us a project which exhibits your issue? We will investigate it, and hopefully will provide a solution or a workaround. Please also provide a reference to this thread, so that we can reply here as well.

    Thank you in advance for your co-operation.

    Best wishes,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Posted on Nov 7, 2008 (permalink)

    Hi all,

    I've encountered the problem with all controls of telerik. The date and numeric's also have this problem. The date and numeric have hidden properties like DbSelectedDate en DbValue, the radcombo has not?

    I think its a shortcomming in the control, especially because these are not trappable errors, clients and users do not understand the error!

    A solution i use is this one:

    1 <telerik:RadComboBox ID="ddl_Grade" Runat="server" AutoCompleteSeparator="|" 
    2     DataSourceID="SqlDataSource_Grade1" DataTextField="GradeDesc" 
    3     DataValueField="LADING_SOORT" DropDownWidth="200px" 
    4     EmptyMessage="<No grades available>" EnableVirtualScrolling="True" 
    5     Filter="Contains" NoWrap="True" Skin="Office2007" AppendDataBoundItems="true" 
    6     SortCaseSensitive="False" DbSelectedValue='<%# Bind("Omschrijving_partij") %>' > 
    7     <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    8     <Items> 
    9         <telerik:RadComboBoxItem Text="(select)" Value="<%# DBNull.Value %>" /> 
    10         <telerik:RadComboBoxItem Text="(Not Yet Known)" Value="?" /> 
    11     </Items> 
    12 </telerik:RadComboBox> 
    13  

    Problem in my case is old dirty data, so when a field is filled with an item not in the list, the hole application crashes.. i would like an option in events where i can check the value, espacialy when in a grid template editing.

  • Simon Simon admin's avatar

    Posted on Nov 7, 2008 (permalink)

    Hi Proovit,

    Indeed, the cases in which the error appears are numerous and this can be frustrating to users, especially if they do not understand the nature of the issue.

    We are going to research on how this situation can be improved or resolved. I will follow up with additional information on the matter as soon as we have results.

    Thank you for bringing our attention to the issue.

    Regards,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Simon Simon admin's avatar

    Posted on Nov 10, 2008 (permalink)

    Hello Proovit,

    I am following up regarding the RadComboBox Exception we discussed previously.

    RadComboBox is designed to be as similar as possible to the MS DropDownList control, so that it can directly replace it in any circumstances.

    Throwing an Exception in this case: there is a selected value and you bind the control to a data source that does not have this value; is inherent to the MS DropDownList, hence to our RadComboBox. So, we do not plan to change this behavior.

    A possible resolution to the situation would be to handle the Grid's ItemDataBound event and validate the ComboBox's Value there; clear the selection if required to avoid the exception.

    Please see this help topic showing how to do that with MS DropDownList (simply replace it with RadComboBox to make it work in your case).

    I hope this is acceptable for you.

    All the best,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Posted on Nov 13, 2008 (permalink)

    Thanks Simon,

    Well ...

    It maybe there are far better programmers... but there is NO WAY to avoid this problem. I've tried it with your example, but there is no triggering of the function before the exception is thrown.

    1 Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound  
    2     If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then  
    3         Dim item As GridEditableItem = e.Item  
    4  
    5         'access/modify the edit item template settings here  
    6         Dim rcm As RadComboBox = CType(item.FindControl("ddl_Grade"), RadComboBox)  
    7         If rcm.Items.FindItemByValue(rcm.SelectedValue) Is Nothing Then  
    8             rcm.Items.Add(New RadComboBoxItem("<Unknown Grade>", rcm.SelectedValue))  
    9         End If  
    10  
    11     End If  
    12 End Sub  
    13  
    14  
    15  

    I've tried an other approach:

    1 <telerik:RadComboBox ID="ddl_Grade" Runat="server" AutoCompleteSeparator="|" OnItemCreated="RadComboBox_ItemDataBound"   
    2     DataSourceID="SqlDataSource_Grade1" DataTextField="LADING_SOORT_Desc" 
    3     DataValueField="LADING_SOORT" DropDownWidth="200px" 
    4     EmptyMessage="<No grades available>" EnableVirtualScrolling="True" 
    5     Filter="Contains" NoWrap="True" Skin="Office2007" AppendDataBoundItems="true" 
    6     SortCaseSensitive="False" SelectedValue='<%# Bind("Omschrijving_partij") %>' > 
    7     <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    8     <Items> 
    9         <telerik:RadComboBoxItem Text="(Select)" Value="<%# DBNull.Value %>" /> 
    10         <telerik:RadComboBoxItem Text="(Not Yet Known)" Value="TBN" /> 
    11     </Items> 
    12 </telerik:RadComboBox> 
    13  
    14  
    15  
    With code like:
    1     Public Sub RadComboBox_ItemDataBound(ByVal sender As ObjectByVal e As System.EventArgs)  
    2         Dim rcm As RadComboBox = CType(sender, RadComboBox)  
    3         If rcm.Items.FindItemByValue(rcm.SelectedValue) Is Nothing Then 
    4             rcm.Items.Add(New RadComboBoxItem("<Unknown Operator>", rcm.SelectedValue))  
    5         End If 
    6     End Sub 
    7  
    8  
    And tried al sorts of events like OnDataBinding OnDataBound OnItemCreated OnItemDataBound OnPreRender OnSelectedIndexChanged

    But no success. Either the list is not completely filled, or the trigger is after the exception. I've spend hours now... I must say it's a sad story. A NotInList event would bee of some use...

    As you say, compatibility with the ms controls is maybe a must, but then again... i bought your components to get rid of such simpleness..

    ANY suggestions would bee welcome!

  • Simon Simon admin's avatar

    Posted on Nov 14, 2008 (permalink)

    Hi Proovit,

    Thank you for providing the code.

    It seems that the issue originates from the fact that the ComboBox has its SelectedValue property bound to a specific column in the data source. If the value, however, does not exist in the data source of the ComboBox, the exception is thrown.

    I suggest you remove the SelectedValue attribute from the ComboBox definition and set it in the Grid's ItemDataBound event handler only if the value exists in the ComboBox.

    If the issue persists, it would be best if you could prepare a simple page or a project which exhibits the issue and send it to us via a formal support ticket. We will inspect your files and will provide the appropriate solution or a workaround.

    Greetings,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Posted on Nov 18, 2008 (permalink)

    Hi Simon.

    Well, i discovered this page, what is simply saying that Microsoft Acknowledges the bug, but "classed this as a Won’t Fix bug." Imagine that! :-)
    See http://david.safitech.com/?p=53

    The problem was "solved" in my case by using a general function, say "RadComboBox_ItemDataBound" to which i set the combobox. Because this procedure is called for every time, and you do not know how many items there are, i delete and than add the selecteditem value if the selectedvalue is not being added. if the selected value is being added, then i remove the dummy and leave it at that. A costly performance downgrade, but in my case the items in a list are not that many.

    <telerik:RadComboBox ID="ddl_Grade" Runat="server" AutoCompleteSeparator="|" OnItemDataBound="RadComboBox_ItemDataBound" 
        DataSourceID="SqlDataSource_PartijLading" DataTextField="lading_soort_Desc" 
        DataValueField="LADINGNUMMER" DropDownWidth="200px" 
        EmptyMessage="(select)" EnableVirtualScrolling="True" 
        Filter="Contains" NoWrap="True" Skin="Office2007" AppendDataBoundItems="true" 
        SortCaseSensitive="False" SelectedValue='<%# Bind("Ladingnummer") %>' > 
        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        <Items> 
            <telerik:RadComboBoxItem Text="(select)" Value="<%# DBNull.Value %>" /> 
            <telerik:RadComboBoxItem Text="(Unknown)" Value="0" /> 
        </Items> 
    </telerik:RadComboBox> 
     
     


    ' Check if value exists  
    Public Sub RadComboBox_ItemDataBound(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim rcm As RadComboBox = CType(sender, RadComboBox)  
        Dim rce As RadComboBoxItemEventArgs = CType(e, RadComboBoxItemEventArgs)  
        Dim rci As RadComboBoxItem = CType(rce.Item, RadComboBoxItem)  
     
        Dim i1 As RadComboBoxItem = rcm.Items.FindItemByValue(rcm.SelectedValue)  
        If i1 Is Nothing Then 
            Call rcm.Items.Add(New RadComboBoxItem("<Unknown Value Not In List!>", rcm.SelectedValue))  
        Else 
            If i1.Text <> cNotInListText Then 
            Else 
                If rci.Value <> rcm.SelectedValue Then 
                    Call i1.Remove()  
                    Call rcm.Items.Add(New RadComboBoxItem(cNotInListText, rcm.SelectedValue))  
                Else 
                    Call i1.Remove()  
                End If 
            End If 
        End If 
    End Sub 
     

  • Simon Simon admin's avatar

    Posted on Nov 21, 2008 (permalink)

    Hi Proovit,

    Thank you for sharing your solution.

    Indeed, it would be better if the bug does not exist and such workarounds are unnecessary. However, since this is the MS DropDownList's current behavior, we will leave RadComboBox the same way as well due to compatibility reasons.

    Once again thank you for your involvement in the matter.


    Kind regards,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Mark Meikle avatar

    Posted on Jun 3, 2010 (permalink)

    This solution worked for me:

    "In case where the bound column allows NULL values as in Mark's case, the best way to avoid the error is to select empty strings instead of the NULLs or convert them to empty strings after the data is selected. Finally, an Item with value = String.Empty or "" should exist in the ComboBox."

  • Ross avatar

    Posted on Jun 15, 2011 (permalink)

    The way I usually solve this problem (with both MS and Telerik versions) is add a null record to the SELECT used to populate the combo list, eg:
    SELECT Value, Text FROM RefTable UNION SELECT NULL, '- Select Value -'
    This ensures that there's a NULL value in the list, so the exception is not thrown.

    ROSCO

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > radcombobox bind errors on null entries