I am using 2 RadComboBoxes(ddlProductCategory and ddlProductCriterion) inside a RadGrid which is inside a RadPanelItem. The second combo box is filled manually when the user selects any option from the first combo box. The first one is bounded to a sqlDataSource; the second one is filled using a data reader. There is no problem inserting data and displaying it in the Rad Grid. However, I keep having errors when I try to Edit any existing record. I have read several forums and have tried to apply the logic but I still have the following error:
“Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Selection out of range. Parameter name: value”
I have tried already to use the ItemDataBound event to pre-populate the radComboBox:
if (e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
if (!(e.Item is IGridInsertItem))
{
RadComboBox combo =(RadComboBox)item.FindControl("ddlProductCriterion");
RadComboBoxItem preselectedItem = new RadComboBoxItem();
preselectedItem.Text = item["Criterion"].Text;
preselectedItem.Value = item["ProductCriterionId"].Text;
combo.Items.Insert(0, preselectedItem);
combo.SelectedIndex = 0;
}
}
//These are my combo boxes
<telerik:GridTemplateColumn HeaderText="Product Category" UniqueName="TemplateColumnProductCategoryId" SortExpression="ProductCategoryId">
<ItemTemplate>
<asp:Label runat="server" ID="ProductCategoryId" Text='<%# Eval("Category")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<br />
<telerik:RadComboBox ID="ddlProductCategory" runat="server" Skin="Web20" SelectedValue='<%# Bind("ProductCategoryId") %>' DataSourceID="dsProductCategoriesJanitorial" DataTextField="Category" DataValueField="Id" AutoPostBack="true" onselectedindexchanged="ddlProductCategory_SelectedIndexChanged1">
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Product Criterion" UniqueName="TemplateColumnProductCriterionId" SortExpression="ProductCriterionId">
<ItemTemplate>
<asp:Label runat="server" ID="ProductCriterionId" Text='<%# Eval("Criterion")%>'> </asp:Label> 
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="ddlProductCriterion" runat="server" Skin="Web20"
SelectedValue='<%# Bind("ProductCriterionId") %>' ></telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
//This is my sqlDatasource located outside any objects (at the bottom of the page)
asp:SqlDataSource ID="dsJanitorialEq" runat="server" ConnectionString="<%$ ConnectionStrings:connLeed %>"
DeleteCommand="DELETE FROM [JanitorialEquipment] WHERE [Id] = @Id" InsertCommand="INSERT INTO JanitorialEquipment(ProjectId, ProductName, PurchaseDate, CostPerItem, QuantityPurchased, ProductCategoryID, ProductCriterionId) VALUES (@ProjectId, @ProductName, @PurchaseDate, @CostPerItem, @QuantityPurchased, @ProductCategoryId, @ProductCriterionId)"
SelectCommand="SELECT JanitorialEquipment.Id, JanitorialEquipment.ProjectId, JanitorialEquipment.ProductName, JanitorialEquipment.PurchaseDate, JanitorialEquipment.CostPerItem, JanitorialEquipment.QuantityPurchased, JanitorialEquipment.ProductCategoryID, JanitorialEquipment.ProductCriterionId, ProductCriterion.Criterion, ProductCategories.Category, ProductSections.Section FROM ProductSections RIGHT OUTER JOIN ProductCategories ON ProductSections.Id = ProductCategories.SectionId RIGHT OUTER JOIN JanitorialEquipment LEFT OUTER JOIN ProductCriterion ON JanitorialEquipment.ProductCriterionId = ProductCriterion.Id ON ProductCategories.Id = JanitorialEquipment.ProductCategoryID WHERE (JanitorialEquipment.ProjectId = @ProjectId)"
UpdateCommand="UPDATE JanitorialEquipment SET ProductName = @ProductName, PurchaseDate = @PurchaseDate, CostPerItem = @CostPerItem, QuantityPurchased = @QuantityPurchased, ProductCategoryID = @ProductCategoryId, ProductCriterionId = @ProductCriterionId WHERE (Id = @Id)">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:QueryStringParameter Name="ProjectId" QueryStringField="projectid" />
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="PurchaseDate" Type="DateTime" />
<asp:Parameter Name="CostPerItem" Type="Decimal" />
<asp:Parameter Name="QuantityPurchased" Type="Int64" />
<asp:Parameter Name="ProductCategoryId" Type="Int32" />
<asp:Parameter Name="ProductCriterionId" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="ProjectId" QueryStringField="projectid" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="PurchaseDate" Type="DateTime" />
<asp:Parameter Name="CostPerItem" Type="Decimal" />
<asp:Parameter Name="QuantityPurchased" Type="Int64" />
<asp:Parameter Name="ProductCategoryId" Type="Int32" />
<asp:Parameter Name="ProductCriterionId" Type="Int32" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
I have tried debugging this and have placed a break point inside the “If” statement above. The error comes before even reaching the breakpoint.
I have tried adding the code above in other events with no success. Do you recommend to use this code in other events? Any suggestions on how to solve this problem would be greatly appreciated. Thanks in advance!