/// <summary>
        /// Handles the UpdateCommand event of the grdSelectionValues control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdSelectionValues_Update(object source, DataGridCommandEventArgs e)
        {
            lblError.Text = String.Empty;
            if (ListItemType.EditItem == e.Item.ItemType)
            {
                var selectionName = (TextBox)e.Item.FindControl("txtEditSelectionName");
                var txtValue      = (TextBox)e.Item.FindControl("txtEditSelectionValue");
                if (selectionName != null && txtValue != null)
                {
                    var customFieldSelectionId = (int)((DataGrid)source).DataKeys[e.Item.ItemIndex];

                    CustomFieldSelection cfs = CustomFieldSelectionManager.GetById(customFieldSelectionId);
                    cfs.Name  = selectionName.Text.Trim();
                    cfs.Value = txtValue.Text.Trim();
                    CustomFieldSelectionManager.SaveOrUpdate(cfs);

                    lblError.Text = String.Empty;

                    foreach (DataGridItem item in grdCustomFields.Items)
                    {
                        var grdSelectionValues = (DataGrid)item.FindControl("grdSelectionValues");
                        if (null == grdSelectionValues)
                        {
                            continue;
                        }

                        grdSelectionValues.ShowFooter    = true;
                        grdSelectionValues.EditItemIndex = -1;
                        BindCustomFieldSelections();
                    }
                }
                ViewState["EditingSubGrid"] = null;
                BindCustomFields();
            }
        }
        /// <summary>
        /// Handles the ItemCommand event of the grdSelectionValues control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdSelectionValues_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            CustomFieldSelection cfs;
            var itemIndex = e.Item.ItemIndex;
            int itemId;
            var grid = source as DataGrid;

            switch (e.CommandName)
            {
            case "up":
                //move row up
                if (itemIndex == 0)
                {
                    return;
                }
                itemId         = Convert.ToInt32(grid.DataKeys[itemIndex]);
                cfs            = CustomFieldSelectionManager.GetById(itemId);
                cfs.SortOrder -= 1;
                CustomFieldSelectionManager.SaveOrUpdate(cfs);
                break;

            case "down":
                //move row down
                if (itemIndex == grid.Items.Count - 1)
                {
                    return;
                }
                itemId         = Convert.ToInt32(grid.DataKeys[itemIndex]);
                cfs            = CustomFieldSelectionManager.GetById(itemId);
                cfs.SortOrder += 1;
                CustomFieldSelectionManager.SaveOrUpdate(cfs);
                break;

            case "add":
                if (Page.IsValid)
                {
                    var txtAddSelectionName  = (TextBox)e.Item.FindControl("txtAddSelectionName");
                    var txtAddSelectionValue = (TextBox)e.Item.FindControl("txtAddSelectionValue");

                    cfs = new CustomFieldSelection
                    {
                        CustomFieldId = Convert.ToInt32(e.CommandArgument),
                        Name          = txtAddSelectionName.Text.Trim(),
                        Value         = txtAddSelectionValue.Text.Trim()
                    };

                    CustomFieldSelectionManager.SaveOrUpdate(cfs);
                }
                break;
            }

            BindCustomFieldSelections();
        }