The rows in my grid need to be updated with the value of a checkbox. The rad dropdown gets a value, then based off of that value, the checkbox gets an assigned value of 'active'(checked) or 'not active'(unchecked). When the user clicks on 'Save', each checked box will then take the ID and associate it to the ID of the dropdown list. Debugging stops at the GridCommandItem line and throws the error `Index was outside the bounds of the array.` Can someone please help me out here? I don't work with arrays much so I don't know how to fix this.
<telerik:RadDropDownList ID="MarketDropDownList" runat="server" DefaultMessage="--Select Market--" Width="200px" DataSourceID="ddlDataSource" DataTextField="MarketName" DataValueField="MarketID" AutoPostBack="true" OnSelectedIndexChanged="MarketDropDownList_SelectedIndexChanged"></telerik:RadDropDownList><telerik:RadGrid ID="radProductsGrid" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" GridLines="None" OnNeedDataSource="radProductsGrid_NeedDataSource" OnSortCommand="radProductsGrid_SortCommand" PageSize="100" CellSpacing="0"> <MasterTableView AllowMultiColumnSorting="false" AllowNaturalSort="false" AllowSorting="true" AutoGenerateColumns="false" Width="100%"> <CommandItemTemplate> <telerik:RadComboBox ID="RadComboBox1" DataTextField="ProductID" DataValueField="ProductID" runat="server"> </telerik:RadComboBox> </CommandItemTemplate> <Columns> <telerik:GridTemplateColumn AllowFiltering="true" HeaderText="Product in Market" ReadOnly="true" UniqueName="TemplateColumnCheckBox"> <HeaderTemplate> <asp:CheckBox ID="selectAllCheckboxes" runat="server" onClick="javascript:SelectDeselectAllCheckboxes(this);" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="ProductInMarketCheckBox" runat="server" /> <asp:HiddenField runat="server" ID="ProductID" Value="ProductID" /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn AllowFiltering="true" DataField="ItemNumber" HeaderText="Item Number" ReadOnly="true" SortExpression="ItemNumber" UniqueName="ItemNumber"> </telerik:GridBoundColumn> <telerik:GridBoundColumn AllowFiltering="true" DataField="ProductName" HeaderText="Product Name" ReadOnly="true" SortExpression="ProductName" UniqueName="ProductName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn AllowFiltering="true" DataField="CategoryName" HeaderText="Category Name" ReadOnly="true" SortExpression="CategoryName" UniqueName="CategoryName"> </telerik:GridBoundColumn> </Columns> </MasterTableView></telerik:RadGrid> <asp:Button ID="btnAddProductToMarket" runat="server" border="0" Text="Save" ToolTip="Select Checkbox and Add Product to Market" OnClick="btnAddProductToMarket_Click" />protected void btnAddProductToMarket_Click(object sender, EventArgs e) { int[] myArray = new int[0]; try { GridCommandItem cmdItem = (GridCommandItem)radProductsGrid.MasterTableView.GetItems(GridItemType.CommandItem)[0]; RadComboBox combo = (RadComboBox)cmdItem.FindControl("RadComboBox1"); string strtxt = combo.Text; foreach (GridDataItem items in radProductsGrid.Items) { if (((CheckBox)items["TemplateColumnCheckBox"].FindControl("ProductInMarketCheckBox")).Checked) { HiddenField ProductID = null; ProductID = (HiddenField)items.FindControl("ProductID"); Array.Resize(ref myArray, myArray.Length + 1); myArray[myArray.Length - 1] = new int(); myArray[myArray.Length - 1] = int.Parse(ProductID.Value); //update query String ConnString = ConfigurationManager.ConnectionStrings["DBConnectingString"].ConnectionString; SqlConnection conn = new SqlConnection(ConnString); String query = @"UPDATE vPanel_MarketMappings SET ProductID = @ProductID, MarketID = @MarketID"; using (SqlCommand cmd = new SqlCommand(query,conn)) { cmd.Parameters.AddWithValue("@ProductID", ProductID); cmd.Parameters.AddWithValue("@MarketID", (CheckBox)items.FindControl("ProductInMarketCheckBox")); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); } } } } catch ( Exception ex ) { LogException( Logging.PageType.ProductManage, Logging.MessageType.Exception, ex.ToString() ); UIUtils.ShowMessageToUser( "OnErrorMesg", this.Page ); } }