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

[Solved] Radcombobox in EditItemTemplate column - Selection out of range

5 Answers 426 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amirtha S
Top achievements
Rank 1
Amirtha S asked on 12 Feb 2010, 09:23 PM
Hi
I am making use of a Radcombobox inside a Radgrid during Edit mode. I get this problem when I have different values for the
DataValueField and DataTextField. When I make use of the same valeus for both, I don't get the error and the Radcombobox is geting populated.

 

<telerik:RadComboBox ID="CbAircraftModelType" runat="server" Skin="Black"   
                            SelectedValue='<%# Bind("modelTypeName") %>' EmptyMessage=" Select Aircraft Type"                             
                            HighlightTemplatedItems="True" DataTextField="modelTypeName" DataValueField="modelTypeId" 
                            EnableTextSelection="False" DataSourceID="SqlDataSource_AircraftType"   
                            OnClientSelectedIndexChanged="cb_OnClientSelectedIndexChanged" /> 

I am making use of a SqlDataSource to populate the Radcombobox.
<asp:SqlDataSource ID="SqlDataSource_AircraftType" runat="server"   
                    ConnectionString="<%$ ConnectionStrings:AvengeConnectionString %>"   
                 SelectCommand="select modelTypeName,modelTypeId from Avenge.dbo.AircraftModelType ">  
            </asp:SqlDataSource> 
I don't have any code for working with this in the code-behind.

This is the error that I am getting:
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) +172  
   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) +102  
   Telerik.Web.UI.RadComboBox.PerformSelect() +37  
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   System.Web.UI.Control.DataBindChildren() +211  
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102  
   System.Web.UI.Control.DataBind() +15  
   Telerik.Web.UI.GridEditFormItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +387  
   Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group) +979  
   Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls) +187  
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1573  
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +782  
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57  
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114  
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31  
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142  
   Telerik.Web.UI.GridTableView.PerformSelect() +28  
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73  
   Telerik.Web.UI.GridTableView.DataBind() +351  
   Telerik.Web.UI.GridTableView.Rebind() +98  
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +395  
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +191  
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37  
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +165  
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37  
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118  
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135  
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10  
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13  
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175  
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565  
 
   
 
Hope someone will be able to help me with this.

Thanks.

5 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 15 Feb 2010, 04:16 PM
Hi Amirtha S,

I would suggest you to set the SelectedValue property to field that is used as DataValueField:

<telerik:RadComboBox ID="CbAircraftModelType" runat="server" Skin="Black"  
                            SelectedValue='<%# Bind("modelTypeId") %>' EmptyMessage=" Select Aircraft Type"                            
                            HighlightTemplatedItems="True" DataTextField="modelTypeName" DataValueField="modelTypeId"
                            EnableTextSelection="False" DataSourceID="SqlDataSource_AircraftType"  
                            OnClientSelectedIndexChanged="cb_OnClientSelectedIndexChanged" />

I hope this helps,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Amirtha S
Top achievements
Rank 1
answered on 15 Feb 2010, 05:59 PM
Sorry this doesn't seem to be working. If I use the set the SelectedValue property to field that is used as DataValueField, the code hangs in the line where Radcombobox is declared.

Pls let me know if there is any other way to solve this problem.

Thanks

0
Amirtha S
Top achievements
Rank 1
answered on 15 Feb 2010, 09:56 PM
sorry I tried it out in a wrong piece of code and the fix that you provided me is working. Thanks for your help.

Now in the same aspx page, I am trying to make a record to be inserted into the DB. Hence I am using the following code behing to make this work, but I am getting a Null Reference Exception. Pls help me fix this problem.
protected void RadGrid_AircraftModels_InsertCommand(object source, GridCommandEventArgs e)  
        {  
 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
            {  
                  
                //GridEditFormItem eeditedItem = e.Item as GridEditFormItem;  
 
                //DropDownList ddlaircrafttypeid = editedItem.FindControl("CbAircraftModelType") as DropDownList;  
                DropDownList ddlaircrafttypeid = (e.Item as GridEditableItem)["modelTypeName"].Controls[0] as DropDownList;  
                SqlDataSource_AircraftModels.InsertParameters["modelTypeId"].DefaultValue = ddlaircrafttypeid.SelectedValue.ToString();  
 
                SqlDataSource_AircraftModels.Insert();  
 
                RadGrid_AircraftModels.Rebind();  
 
            }  
        } 

Here is the aspx page contents:
 <telerik:RadGrid ID="RadGrid_AircraftModels" runat="server" DataSourceID="SqlDataSource_AircraftModels"   
                        AutoGenerateColumns="False"    
                        Skin="Black" GridLines="None"   
                        Width="95%"   
                        AutoGenerateDeleteColumn="True" 
                        AutoGenerateEditColumn="True"   
                 oneditcommand="RadGrid_AircraftModels_EditCommand"   
                 onitemdatabound="RadGrid_AircraftModels_ItemDataBound"   
                 ondatabinding="RadGrid_AircraftModels_DataBinding"   
                 oninsertcommand="RadGrid_AircraftModels_InsertCommand"   
                 onitemcreated="RadGrid_AircraftModels_ItemCreated" > 
                    
                 <MasterTableView DataKeyNames="modelId"  CommandItemDisplay="Top"   
                    DataSourceID="SqlDataSource_AircraftModels" CssClass="radgrid" EditMode="InPlace">  
                    <Columns> 
                        <telerik:GridBoundColumn HeaderText="Model Id" DataField="modelId"   
                            UniqueName="modelId" ReadOnly="true" Visible="False" /> 
                            <telerik:GridBoundColumn HeaderText="Model Type Id" DataField="modelTypeId"   
                            UniqueName="modelTypeId" ReadOnly="true" Visible="False" /> 
                        <telerik:GridTemplateColumn DataField="name" DefaultInsertValue=""   
                            HeaderText="Aircraft Model" UniqueName="name" ItemStyle-HorizontalAlign="Center" > 
                            <EditItemTemplate> 
                                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>'></asp:TextBox> 
                            </EditItemTemplate> 
                            <ItemTemplate> 
                                <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>'></asp:Label> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn DataField="modelTypeName" DefaultInsertValue=""   
                            HeaderText="Aircraft Type" UniqueName="modelTypeName" ItemStyle-HorizontalAlign="Center">  
                            <EditItemTemplate> 
                            <telerik:RadComboBox ID="CbAircraftModelType" runat="server" Skin="Black"   
                            SelectedValue='<%# Bind("modelTypeId") %>' EmptyMessage=" Select Aircraft Type"                             
                            HighlightTemplatedItems="True" DataTextField="modelTypeName" DataValueField="modelTypeId" 
                            EnableTextSelection="False" DataSourceID="SqlDataSource_AircraftType"   
                            OnClientSelectedIndexChanged="" /> 
                              
                            </EditItemTemplate> 
                            <ItemTemplate> 
                                <asp:Label ID="modelTypeNameLabel" runat="server"   
                                    Text='<%# Eval("modelTypeName") %>'></asp:Label> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                          
                    </Columns> 
                </MasterTableView> 
                </telerik:RadGrid> 
                 
                 <asp:SqlDataSource ID="SqlDataSource_AircraftModels" runat="server"   
                    ConnectionString="<%$ ConnectionStrings:AvengeConnectionString %>"   
                 SelectCommand="select a.name, b.modelTypeName, a.modelId,b.modelTypeId from Avenge.dbo.AircraftModel as a   
                                join Avenge.dbo.AircraftModelType as b on a.modelTypeId = b.modelTypeId order by a.name asc"   
                 DeleteCommand="delete from AircraftModelType where modelId =@modelId "   
                 InsertCommand="INSERT INTO AircraftModel(modelTypeId, name) VALUES (@modelTypeId,@name)">  
                     <DeleteParameters> 
                         <asp:ControlParameter ControlID="RadGrid_AircraftModels" Name="modelId"   
                             PropertyName="SelectedValue" /> 
                     </DeleteParameters> 
                     <InsertParameters> 
                         <asp:ControlParameter ControlID="RadGrid_AircraftModels" Name="modelTypeId"   
                             PropertyName="SelectedValue" /> 
                         <asp:ControlParameter ControlID="RadGrid_AircraftModels" Name="name"   
                             PropertyName="SelectedValue" /> 
                     </InsertParameters> 
            </asp:SqlDataSource> 
            <asp:SqlDataSource ID="SqlDataSource_AircraftType" runat="server"   
                    ConnectionString="<%$ ConnectionStrings:AvengeConnectionString %>"   
                 SelectCommand="select modelTypeName,modelTypeId from Avenge.dbo.AircraftModelType ">  
            </asp:SqlDataSource> 

0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Feb 2010, 06:27 AM
Hi,

Try the code snippet below to access  the RadComboBox in the insert command.

C#
 protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
        { 
            GridDataInsertItem insertItem = (GridDataInsertItem)e.Item; 
            RadComboBox rbList= (RadComboBox)insertItem["ColumnUniqueName"].FindControl("rbList"); 
 
        } 


Hope this helps.

Thanks,
Princy
0
Amirtha S
Top achievements
Rank 1
answered on 16 Feb 2010, 02:46 PM
Hi princy,
Thanks a ton. The code that you provided fixed my problem.
Tags
Grid
Asked by
Amirtha S
Top achievements
Rank 1
Answers by
Martin
Telerik team
Amirtha S
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or