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

[Solved] Combobox in detailtable : Selection out of range Parameter name: value

12 Answers 280 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cecilie Nordbø
Top achievements
Rank 1
Cecilie Nordbø asked on 12 May 2011, 02:29 PM
Hi.
I have a grid with a detailtable contain two combobox. The comboBox works find for insert but not editing. It seems like the combobox values is not filled up before reaching the html code where i have SelectedValue='<%#Bind("Route1")%>'. The comboboxies are filled up by RadGridSamband_ItemDataBound. If i remove SelecetedValue the errror disappear but than the value from the combobox is not saved. (I used LinqDataSource with automaticUpdates.) I have tried some solution in the forum without luck.  How can i solved this problem?

The code i am using is:
 
protected void RadGridSamband_ItemDataBound(object sender, GridItemEventArgs e)
      {           
          if (e.Item is GridDataInsertItem)
          {
              SetSambandAndDistancColumnWidth(e);               
              if (e.Item.OwnerTableView.Name == "GridDistance")
              {
                  SetFocusOnField(e, "Distancenumber");
                  FillComboboxWithRoutes(e, "Route1ComboBox", false);
                  FillComboboxWithRoutes(e, "Route2ComboBox", false);
              }
              else
              {
                  SetFocusOnField(e, "Sambandnumber");
              }
          }        
          else if (e.Item.IsInEditMode)
          {
              SetSambandAndDistancColumnWidth(e);               
              if (e.Item.OwnerTableView.Name == "GridDistance")
              {               
                  SetFocusOnField(e, "Distancenumber");
                  FillComboboxWithRoutes(e, "Route1ComboBox", true);
                  FillComboboxWithRoutes(e, "Route2ComboBox", true);
              }
              else
              {
                  SetFocusOnField(e, "Sambandnumber");
              }
          }          
      }

<telerik:RadGrid ID="RadGridSamband" runat="server" AllowSorting="True"
                   AutoGenerateColumns="False" DataSourceID="SambandDataSource" GridLines="None"
                   Culture="Norwegian, BokmÃ¥l (Norway)" ShowStatusBar="True"                     
                   onitemdeleted="RadGridSamband_ItemDeleted"
                   oniteminserted="RadGridSamband_ItemInserted"
                   onitemupdated="RadGridSamband_ItemUpdated"
                   onitemdatabound="RadGridSamband_ItemDataBound"
                   onitemcommand="RadGridSamband_ItemCommand" AllowAutomaticDeletes="True"
                   AllowAutomaticInserts="True" AllowAutomaticUpdates="True">       
           <MasterTableView DataKeyNames="Id" DataSourceID="SambandDataSource" CommandItemDisplay="Top" EditMode="InPlace" Name="Samband">
               <DetailTables>
                   <telerik:GridTableView runat="server" CommandItemDisplay="Top" DataSourceID="DistanceDataSource" EditMode="InPlace" HierarchyDefaultExpanded="True" Name="GridDistance" DataKeyNames="Id">
                       <ParentTableRelation><telerik:GridRelationFields DetailKeyField="SambandId" MasterKeyField="Id" /></ParentTableRelation>
                   <CommandItemSettings ExportToPdfText="Export to Pdf" />
                   <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"><HeaderStyle Width="20px" /></RowIndicatorColumn>
                   <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"><HeaderStyle Width="20px" /></ExpandCollapseColumn>
                       <Columns>
                           <telerik:GridBoundColumn  UniqueName="SambandId" DataField="SambandId" HeaderText="SId" ReadOnly="true" AllowFiltering="false"><HeaderStyle Width="20px"></HeaderStyle></telerik:GridBoundColumn>  
                           <telerik:GridNumericColumn  UniqueName="Distancenumber"  DataType="System.Int32" HeaderText="Strekningsnr." DataField="Distancenumber" SortExpression="Distancenumber"><HeaderStyle Width="70px"></HeaderStyle><ItemStyle HorizontalAlign="Right" /></telerik:GridNumericColumn>            
                           <telerik:GridNumericColumn  UniqueName="Distancelength" DataType="System.Int32" HeaderText="Strekningslengde" DataField="Distancelength" SortExpression="Distancelength"><HeaderStyle Width="70px"></HeaderStyle><ItemStyle HorizontalAlign="Right"/></telerik:GridNumericColumn>                                                            
                           <telerik:GridTemplateColumn DataField="Route1" DataType="System.String" SortExpression="Route1" UniqueName="Route1" HeaderText="Rute">                    
                               <ItemTemplate><%#DataBinder.Eval(Container.DataItem, "Route1") %></ItemTemplate>
                               <EditItemTemplate>
                                   <telerik:RadComboBox runat="server" id="Route1ComboBox" DataValueField="Route1" HighlightTemplatedItems="true" EmptyMessage="Velg et element"  AutoPostBack="true" Height="100px" Width="180px" AppendDataBoundItems="true"  OnSelectedIndexChanged="Route1ComboBox_SelectedIndexChanged" AllowCustomText="true"  SelectedValue='<%#Bind("Route1")%>'>
                                       <Items><telerik:RadComboBoxItem runat="server" Text="" Value=""/></Items>
                                   </telerik:RadComboBox>
                                   <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Text="*" ForeColor="Red" ControlToValidate="Route1ComboBox" runat="server"/>
                               </EditItemTemplate>
                           </telerik:GridTemplateColumn>
                           <telerik:GridTemplateColumn DataField="Route2" DataType="System.String" SortExpression="Route2" UniqueName="Route2" HeaderText="Rute">                    
                               <ItemTemplate><%#DataBinder.Eval(Container.DataItem, "Route2") %></ItemTemplate>
                               <EditItemTemplate>
                                   <telerik:RadComboBox runat="server" id="Route2ComboBox" DataValueField="Route2" HighlightTemplatedItems="true" EmptyMessage="Velg et element" AllowCustomText="true" AutoPostBack="true" Height="100px" Width="180px" AppendDataBoundItems="true" OnSelectedIndexChanged="Route2ComboBox_SelectedIndexChanged"  SelectedValue='<%#Bind("Route2")%>'>
                                       <Items><telerik:RadComboBoxItem runat="server" Text="" Value=""/></Items>
                                   </telerik:RadComboBox>                           
                               </EditItemTemplate>
                           </telerik:GridTemplateColumn>     
                           <telerik:GridEditCommandColumn CancelText="Avbryt" EditText="Endre" InsertText="Sett inn" UpdateText="Oppdater"><HeaderStyle Width="105px"></HeaderStyle><ItemStyle HorizontalAlign="Right" /></telerik:GridEditCommandColumn>      
                           <telerik:GridButtonColumn HeaderStyle-Width="40px" CommandName="Delete" Text="Slett" UniqueName="column2" ConfirmDialogType="RadWindow" ConfirmText="Er du sikker pÃ¥ at du vil slette elementet?" ConfirmTitle="Bekreft sletting"><HeaderStyle Width="40px"></HeaderStyle></telerik:GridButtonColumn>                              
                       </Columns>
                   <EditFormSettings><EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn></EditFormSettings>
               </telerik:GridTableView>
               </DetailTables>
               <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
               <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"><HeaderStyle Width="20px"></HeaderStyle></RowIndicatorColumn>
               <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True"><HeaderStyle Width="20px"></HeaderStyle></ExpandCollapseColumn>
               <Columns>
                   <telerik:GridTemplateColumn DefaultInsertValue="false" UniqueName="IsSelected" HeaderStyle-Width="40px" HeaderText="Velg" AllowFiltering="false">
                       <ItemTemplate>
                           <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%#Eval("IsSelected")%>' Tooltip="Brukes for Ã¥ merke av hvilken samband som skal være med ved generering av ferjedatabankfil(er)."/>                                    
                       </ItemTemplate>
                       <EditItemTemplate></EditItemTemplate>
                   <HeaderStyle HorizontalAlign="Center" /><ItemStyle HorizontalAlign="center"/></telerik:GridTemplateColumn>
                   <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column" HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id"></telerik:GridBoundColumn>             
                   <telerik:GridNumericColumn DataField="Sambandnumber" DataType="System.Int32" HeaderText="Sambandnr." SortExpression="Sambandnumber" UniqueName="Sambandnumber"><HeaderStyle Width="100px"></HeaderStyle></telerik:GridNumericColumn>
                   <telerik:GridBoundColumn DataField="SambandFrom" HeaderText="Fra navn pÃ¥ sambandet" SortExpression="SambandFrom" UniqueName="SambandFrom"><HeaderStyle Width="180px"></HeaderStyle></telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="SambandTo" HeaderText="Til navn pÃ¥ sambandet" SortExpression="SambandTo" UniqueName="SambandTo"><HeaderStyle Width="180px"></HeaderStyle></telerik:GridBoundColumn>                   
                   <telerik:GridCheckBoxColumn DataField="HasFerryAttached" DataType="System.Boolean" HeaderText="Har ferje" SortExpression="HasFerryAttached" UniqueName="HasFerryAttached"><HeaderStyle Width="80px"></HeaderStyle></telerik:GridCheckBoxColumn>
                    <telerik:GridEditCommandColumn CancelText="Avbryt" EditText="Endre" InsertText="Sett inn" UpdateText="Oppdater"><HeaderStyle Width="105px"></HeaderStyle><ItemStyle HorizontalAlign="Right" /></telerik:GridEditCommandColumn>      
                   <telerik:GridButtonColumn HeaderStyle-Width="40px" CommandName="Delete" Text="Slett" UniqueName="column1" ConfirmDialogType="RadWindow" ConfirmText="Er du sikker pÃ¥ at du vil slette elementet?" ConfirmTitle="Bekreft sletting"><HeaderStyle Width="40px"></HeaderStyle></telerik:GridButtonColumn>                                    
               </Columns>
               <EditFormSettings><EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn></EditFormSettings>
           </MasterTableView>
           <FilterMenu EnableImageSprites="False"></FilterMenu>
           </telerik:RadGrid>

12 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 17 May 2011, 03:07 PM
Hello Cecilie,

In order to implement the desired functionality, I recommend that you set the selected value of the combo in the ItemDataBound event handler after the control is filled with data.

I hope this helps.

Best wishes,
Mira
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
Cecilie Nordbø
Top achievements
Rank 1
answered on 18 May 2011, 01:18 PM
If i do that, than the insert mode does not work properly because the selected value from the combobox is null when saving. So how can i solved the null value if i go for the suggested solution?
0
Mira
Telerik team
answered on 20 May 2011, 01:44 PM
Hello Cecilie,

Could you please set the selected value only in the place shown in the code below:
protected void RadGridSamband_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataInsertItem)
    {
        SetSambandAndDistancColumnWidth(e);
        if (e.Item.OwnerTableView.Name == "GridDistance")
        {
            SetFocusOnField(e, "Distancenumber");
            FillComboboxWithRoutes(e, "Route1ComboBox", false);
            FillComboboxWithRoutes(e, "Route2ComboBox", false);
        }
        else
        {
            SetFocusOnField(e, "Sambandnumber");
        }
    }
    else if (e.Item.IsInEditMode)
    {
        SetSambandAndDistancColumnWidth(e);
        if (e.Item.OwnerTableView.Name == "GridDistance")
        {
            SetFocusOnField(e, "Distancenumber");
            FillComboboxWithRoutes(e, "Route1ComboBox", true);
            FillComboboxWithRoutes(e, "Route2ComboBox", true);
            //set the selected value of the combo here
        }
        else
        {
            SetFocusOnField(e, "Sambandnumber");
        }
    }
}

I hope this helps.

All the best,
Mira
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
Cecilie Nordbø
Top achievements
Rank 1
answered on 23 May 2011, 07:15 AM
I have tried that and the selected value is null when saving. Here is my code for FillCombobxWithRoutes that is called by the RadGridSamband_ItemDataBound:

protected void FillComboboxWithRoutes(GridItemEventArgs e, string comboBoxName, bool isInEditMode)
       {
           if (!(e.Item is GridDataItem))
               return;
 
           var editItem = (GridDataItem)e.Item;
           var comboBox = (RadComboBox)editItem.FindControl(comboBoxName);
           comboBox.Items.Clear();
 
           List<Route> routes = FerrydatabankBiz.GetDistinctRoutes(logger);
           if (routes.Count == 0)
           {
               comboBox.EmptyMessage = "Fant ingen ruter...";
           }
           else
           {
               foreach (var route in routes)
               {
                   var item = new RadComboBoxItem
                   {                       
                       Text = route.RouteNumber + " " + route.Name.Trim(),
                       Value = route.RouteNumber + " " + route.Name.Trim()
                   };
                   comboBox.Items.Add(item);
               }
                                      
 
               if (isInEditMode && e.Item.DataItem is Distance)
               {
                   var distance = e.Item.DataItem as Distance;
                   comboBox.SelectedValue = valueField.Contains("1") ? distance.Route1 : distance.Route2;
               }
           }
       }

I really need to solv this if any one can help, plz.
0
Cecilie Nordbø
Top achievements
Rank 1
answered on 24 May 2011, 02:10 PM
I have tried to do the suggested solution also with setting the selectedvalue in the html code but than i am back to start again where i got the selection out of range Parameter when i edit an item. If i have the selectedValue in the html code, the edit mode is not working but insert mode is. If i remove the selectedValue in the html code than edit mode work but insert mode not.

When i edit an item when the selectedValue is in the html code, the ItemDataBound event is call where the e.Item is of type GridCommandItem, GridPagerItem or GridHeaderItem and than it tried to execute the SelectedValue in the html code before the combobox is filled up. So which event can i used to filled up the combobox?


I have spent over a week on this problem and searched the forums looking for an answer with no luck.
Please can I get a response to my post.
0
Maria Ilieva
Telerik team
answered on 26 May 2011, 11:30 AM
Hello Cecilie,

Please ensure that you do not set the selected value when the item is in insert mode but only when is GridDataEditableItem as the code provided in our last post shows. Please ensure that the previously provided code works correctly for you.

Greetings,
Maria Ilieva
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
Cecilie Nordbø
Top achievements
Rank 1
answered on 26 May 2011, 12:07 PM
I am not setting the selected value in insert mode. In  FillComboboxWithRoutes before I set the selected value I check what mode it is.So that not the problem.

Since I can't find any solution on this and will not remove the combobox that make the trouble, I remove the edit button for the detailtable although I am not happy with such solution.
0
Ricardo Pinto
Top achievements
Rank 1
answered on 08 Nov 2011, 06:52 PM
Hello!

I have almost the same scenario:  I have a grid with a template column with three readonly comboboxes in itemtemplate and three enabled comboboxes in edititemtemplate, all of them with SelectedValue='<%#Bind("Field")%>'.

I'm using the 2011.2.1018.40 dll version, the grid uses SqlDataSource with automatic operations (insert, update, delete) and the comboboxes are populated with declarative LinqDataSources.

The automatic operations were working fine but sometimes I got the same error: Selection out of range Parameter name: value on page load (in the typical yellow server error page). This was due to changes which occured in other areas of the application, causing one of the items in the grid's datasource no longer beeing available in the radcomboxes.

In order to try to avoid this error, I first removed the SelectedValue='<%#Bind("Field")%>' from the six comboboxes and used the ItemDataBound event to set the selectedvalue (only if contained in the comboboxes item collection).

This solved the 'Selection out of range Parameter name: value' error on load and the readonly comboboxes were correctly filled, but the automatic insert no longer worked as intended (the comboboxes selected values apparently were not kept and the fields were inserted with null values).

After I found this post, and implemented a similar logic as Cecile (also filling the combos in code behind, instead of using declarative datasources), the insert operation started working normally again but now I cannot edit items, just like Cecile described! When I click the edit button, the page loads for a while but nothing happens and on firebug I get
'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Selection out of range Parameter name: value' when calling method: [nsIDOMEventListener::handleEvent] -originalHandler.handleEvent(event). 

Can you please provide a working sample of a datagrid with automatic operations and comboboxes in a templatecolumn (itemtemplate and edititemtemplate) which can avoid the  'Selection out of range Parameter name: value' error? Or are we trying something impossible here? :)

Thanks in advance for your help!
Best regards,

Ricardo.
0
Maria Ilieva
Telerik team
answered on 10 Nov 2011, 02:57 PM
Hi Ricardo,

I would suggest you to review the kb article below which provide working example for the required scenario. Test the provided approach and let me know if it works for you.
http://www.telerik.com/support/kb/aspnet-ajax/grid/using-radcombobox-as-editor-in-template-column-of-radgrid.aspx

All the best,
Maria Ilieva
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
0
John
Top achievements
Rank 1
answered on 22 Feb 2012, 02:52 PM
I'm having the same problem. My only comment is this: As much as we paid for the licensing fees, WE shouldn't have to do this much work to fix it.
0
Iana Tsolova
Telerik team
answered on 24 Feb 2012, 11:00 AM
Hi John,

Can you elaborate a bit more on your exact issue? If you are getting error when trying to set the SelectedValue property through the markup, there is an explanation for that. First, you can see the this property event does not come in the Itellisense, this is the same for the ASP:DropDownList. You can however set it, but you need to make sure the SelectedValue will be the value of some of the existing items. If such item, with Value set to the SelectedValue is not found, then getting an error is rather expected.
However solving this issue with RadComboBox is much easier than with the ASP:DropDownList. Here the Text property of the RadComboBox comes handy and you can set it instead of using the SelectedValue one. So you can see that we have taken care for this scenario.

Give it a try and let me know if it works for you.

All the best,
Iana Tsolova
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.
0
Tim
Top achievements
Rank 1
answered on 17 May 2013, 11:07 AM
This should work.  All you need to do is add an event handler for the UpdateCommand and InsertCommand events of the Grid, and the manually update your entity/object with data from any Templated columns...

protected void OnGridUpdateCommand(object sender, GridCommandEventArgs e)
{
    var gridItem = (e.Item as GridEditableItem);
     
    // Get the edited entity
    var agreementID = (int)gridItem.GetDataKeyValue("AgreementID");
    var partyID = (Guid)gridItem.GetDataKeyValue("PartyID");
    var roleID = (int)gridItem.GetDataKeyValue("RoleID");
    var effectiveDate = (DateTime)gridItem.GetDataKeyValue("EffectiveDate");
    var party = this.agreementParties.FirstOrDefault(ap =>
        ap.AgreementID == agreementID
        && ap.PartyID == partyID
        && ap.RoleID == roleID
        && ap.EffectiveDate == effectiveDate
        );
 
    // Update the entity
    gridItem.UpdateValues(party);
             
    // Manually update Templated column values
    var partyName = (RadComboBox)gridItem.FindControl("PartyName");
    party.PartyID = new Guid(partyName.SelectedValue);
 
    // TODO: Update Navigation properties of Entities before allowing re-binding...
    // ex. party.Party = db.Parties.FirstOrDefault(p => p.ID == party.PartyID);
}

This is necessary because the previous suggestion in this thread about handling the DataItemBound event is useless because the Grid doesn't actually rebind until AFTER the GridItem has been Inserted/Edited.  You can tell because the e.Item.DataItem is null/Nothing!  This makes sense because why would you want to bind the grid twice?  Hope this helps.
Tags
Grid
Asked by
Cecilie Nordbø
Top achievements
Rank 1
Answers by
Mira
Telerik team
Cecilie Nordbø
Top achievements
Rank 1
Maria Ilieva
Telerik team
Ricardo Pinto
Top achievements
Rank 1
John
Top achievements
Rank 1
Iana Tsolova
Telerik team
Tim
Top achievements
Rank 1
Share this question
or