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

[Solved] Save edits with Grouping

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RB
Top achievements
Rank 1
RB asked on 24 Jun 2014, 10:10 PM
I have a radgrid with grouping enabled.
this._RadGrid1.ClientSettings.Selecting.AllowRowSelect = true;
 this._RadGrid1.AllowMultiRowSelection = true;
 this._RadGrid1.ClientSettings.AllowGroupExpandCollapse = true;
 this._RadGrid1.ClientSettings.AllowKeyboardNavigation = true;
 this._RadGrid1.EnableGroupsExpandAll = true;
 this._RadGrid1.EnableHeaderContextFilterMenu = true;
 this._RadGrid1.GroupingEnabled = true;
 this._RadGrid1.ShowGroupPanel = true;
 this._RadGrid1.AllowFilteringByColumn = false;
 
 this._RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
 this._RadGrid1.MasterTableView.EnableHeaderContextMenu = true;
 this._RadGrid1.MasterTableView.EnableHeaderContextFilterMenu = true;        
 this._RadGrid1.MasterTableView.NoMasterRecordsText = "No BAN Assignments found";
                      
 this._RadGrid1.MasterTableView.DataKeyNames = new string[] { this._PriceDealProductBanTable.PriceDealEntityProductItemIdColumn.ColumnName };
 this._RadGrid1.MasterTableView.ClientDataKeyNames = new string[] { this._PriceDealProductBanTable.PriceDealEntityProductItemIdColumn.ColumnName };                                
 this._RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
The grid also has a text box template as followS:
templateColumn = new GridTemplateColumn();
templateColumnName = this._PriceDealProductBanTable.BillingAccountNumberColumn.ColumnName;
this._RadGrid1.MasterTableView.Columns.Add(templateColumn);
templateColumn.ItemTemplate = new TextBoxTemplate(templateColumnName);
templateColumn.HeaderText = "BAN";
templateColumn.DataField = templateColumnName;      
templateColumn.Groupable = false;

When the records are grouped, and if i select a row and change the value of the textbox, on click of save button, I get the previous value and not the new value which needs to be saved! But if the records are not grouped, it works fine!

2 Answers, 1 is accepted

Sort by
0
RB
Top achievements
Rank 1
answered on 24 Jun 2014, 10:15 PM
It also works fine with default grouping. But when I add an additional column to be grouped by, on save it fails to get the new value in the textbox!
0
RB
Top achievements
Rank 1
answered on 24 Jun 2014, 10:36 PM
Also I have many issues expanding and collapsing rows. For instance when I Collapse all after grouping, and then try to expand the 1st row, instead the 2nd row expands! Also I can expand/collapse only 1 row at a time.
Here is the entire code:
class AssignBanGridCtrl : WebControl
{
    #region Fields
    private RadAjaxLoadingPanel _RadLoadingPanel = new RadAjaxLoadingPanel();
    private RadAjaxPanel _RadAjaxPanel = new RadAjaxPanel();
    private RadGrid _RadGrid1 = new RadGrid();    
    private PriceDealProductBanTable _PriceDealProductBanTable = new PriceDealProductBanTable();
    private PriceDealProposal _Proposal = null;   
    private bool _HasOrderRequest = false;
    private GXButton _btnCopyToSelect=new GXButton();
    private GXButton _btnSaveSelected=new GXButton();
    private GXTextBox _TbBAN = new GXTextBox();
 
    private bool _IsSupplementOrChangeQuote;
 
    #endregion
 
     #region Constructors
 
    public AssignBanGridCtrl(PriceDealProposal proposal, bool hasOrderRequest)
        : base()
    {
        this._Proposal = proposal;
        this._HasOrderRequest = hasOrderRequest;
    }
    public AssignBanGridCtrl(PriceDealProposal proposal, bool hasOrderRequest, bool IsSupplementOrChangeQuote)
        : base()
    {
        this._Proposal = proposal;
        this._HasOrderRequest = hasOrderRequest;
        this._IsSupplementOrChangeQuote = IsSupplementOrChangeQuote;
    }
 
    #endregion
 
   #region Overrides
 
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
       
        this._RadLoadingPanel.ID = "_RadLoadingPanel";
        this._RadLoadingPanel.Transparency = 30;
        this._RadLoadingPanel.Skin = "WebBlue";
        this._RadLoadingPanel.BackgroundPosition = AjaxLoadingPanelBackgroundPosition.Center;
 
        #region Grid1
        this._RadGrid1.ID = "RadGrid1";
         this._RadGrid1.Skin = "WebBlue";
         this._RadGrid1.Width = Unit.Percentage(100);
         this._RadGrid1.GridLines = GridLines.None;
         this._RadGrid1.PageSize = 100;
         this._RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
 
         this._RadGrid1.AllowPaging = true;
         this._RadGrid1.AllowSorting = true;
         this._RadGrid1.AutoGenerateColumns = false;
         this._RadGrid1.AllowFilteringByColumn = true;
         this._RadGrid1.EnableLinqExpressions = false;
         this._RadGrid1.AllowAutomaticInserts = false;
         this._RadGrid1.AllowAutomaticUpdates = false;
         this._RadGrid1.AllowAutomaticDeletes = false;                         
       
        this._RadGrid1.ClientSettings.Selecting.AllowRowSelect = true;
        this._RadGrid1.AllowMultiRowSelection = true;
        this._RadGrid1.ClientSettings.AllowGroupExpandCollapse = true;
        this._RadGrid1.ClientSettings.AllowKeyboardNavigation = true;
        this._RadGrid1.EnableGroupsExpandAll = true;
        this._RadGrid1.EnableHeaderContextFilterMenu = true;
        this._RadGrid1.GroupingEnabled = true;
        this._RadGrid1.ShowGroupPanel = true;
        this._RadGrid1.AllowFilteringByColumn = false;
 
        this._RadGrid1.ClientSettings.DataBinding.EnableCaching = true;
        this._RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
        this._RadGrid1.MasterTableView.EnableHeaderContextMenu = true;
        this._RadGrid1.MasterTableView.EnableHeaderContextFilterMenu = true;
        //this._RadGrid1.ClientSettings.ClientEvents.OnRowSelected = "OnRowSelected";
        //this._RadGrid1.ClientSettings.ClientEvents.OnCommand = "function(){}";
        this._RadGrid1.MasterTableView.NoMasterRecordsText = "No BAN Assignments found";
                             
        this._RadGrid1.MasterTableView.DataKeyNames = new string[] { this._PriceDealProductBanTable.PriceDealEntityProductItemIdColumn.ColumnName };
        this._RadGrid1.MasterTableView.ClientDataKeyNames = new string[] { this._PriceDealProductBanTable.PriceDealEntityProductItemIdColumn.ColumnName };                                
        this._RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
                
        GridBoundColumn boundColumn = new GridBoundColumn();
        string columnName;
 
        #region Default grouping
        GridGroupByExpression expression = new GridGroupByExpression();
        GridGroupByField gridGroupByField = new GridGroupByField();
        gridGroupByField = new GridGroupByField();
        gridGroupByField.FieldName = this._PriceDealProductBanTable.DescriptionColumn.ColumnName;
        gridGroupByField.HeaderText = "Location";
        expression.SelectFields.Add(gridGroupByField);
 
        gridGroupByField = new GridGroupByField();
        gridGroupByField.FieldName = this._PriceDealProductBanTable.DescriptionColumn.ColumnName;
        gridGroupByField.HeaderText = "Location";
        expression.GroupByFields.Add(gridGroupByField);
 
        this._RadGrid1.MasterTableView.GroupByExpressions.Add(expression);
        #endregion
 
        #region RadGrid Columns
        GridClientSelectColumn selectAll = new GridClientSelectColumn();
        selectAll.UniqueName = "SelectOne";           
         
        this._RadGrid1.MasterTableView.Columns.Add(selectAll);
 
        string templateColumnName;
        GridTemplateColumn templateColumn = new GridTemplateColumn();                              
 
        columnName = this._PriceDealProductBanTable.DescriptionColumn.ColumnName; ;
        boundColumn = new GridBoundColumn();
        this._RadGrid1.MasterTableView.Columns.Add(boundColumn);           
        boundColumn.DataField = columnName;
        boundColumn.HeaderText = "Location";
        boundColumn.ReadOnly = true;
      
        columnName = this._PriceDealProductBanTable.CatalogProductColumn.ColumnName;
        boundColumn = new GridBoundColumn();
        this._RadGrid1.MasterTableView.Columns.Add(boundColumn);        
        boundColumn.DataField = columnName;
        boundColumn.HeaderText = "Product";
        boundColumn.ReadOnly = true;          
 
        columnName = this._PriceDealProductBanTable.CountryColumn.ColumnName;
        boundColumn = new GridBoundColumn();        
        this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = columnName;
        boundColumn.ReadOnly = true;
        boundColumn.HeaderText = "Country";
 
        columnName = this._PriceDealProductBanTable.StateColumn.ColumnName; 
        boundColumn = new GridBoundColumn();       
        this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
        boundColumn.HeaderText = "State/Province";
        boundColumn.ReadOnly = true;
        boundColumn.DataField = columnName;
 
        columnName = this._PriceDealProductBanTable.SourceSystemTypeDescriptionColumn.ColumnName;
        boundColumn = new GridBoundColumn();         
        this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = columnName;
        boundColumn.ReadOnly = true;
        boundColumn.HeaderText = "OE System";
 
        //columnName = this._PriceDealProductBanTable.BillingAccountNumberColumn.ColumnName;
        //boundColumn = new GridBoundColumn();
        //this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
        //boundColumn.DataField = columnName;
        //boundColumn.HeaderText = "BAN";
        //boundColumn.UniqueName = "BAN";
        //boundColumn.AllowFiltering = false;
                    
        templateColumn = new GridTemplateColumn();
        templateColumnName = this._PriceDealProductBanTable.BillingAccountNumberColumn.ColumnName;
        this._RadGrid1.MasterTableView.Columns.Add(templateColumn);
        templateColumn.ItemTemplate = new TextBoxTemplate(templateColumnName);
        templateColumn.HeaderText = "BAN";
        templateColumn.DataField = templateColumnName;      
        templateColumn.Groupable = false;
 
        if (this._IsSupplementOrChangeQuote)
        {
            templateColumnName = this._PriceDealProductBanTable.AssetServiceIdColumn.ColumnName;
            templateColumn = new GridTemplateColumn();
            this._RadGrid1.MasterTableView.Columns.Add(templateColumn);
            templateColumn.ItemTemplate = new TextBoxTemplate(templateColumnName);
            templateColumn.HeaderText = "Asset/Service ID";
            templateColumn.DataField = templateColumnName;              
            templateColumn.Exportable = false;
        }
 
        //GridEditCommandColumn gridEditCommandColumn = new GridEditCommandColumn();
        //gridEditCommandColumn.UniqueName = "GridEditCommandColumn";
        //this._RadGrid1.MasterTableView.Columns.Add(gridEditCommandColumn);
        //this._RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace;
        #endregion
        #endregion
 
 
        this._RadAjaxPanel.Controls.Add(this._RadLoadingPanel);
        this._RadAjaxPanel.Controls.Add(this._RadGrid1);
        if (!this._IsSupplementOrChangeQuote)
        {
            this._TbBAN.ID = "TbBAN";
            this._TbBAN.ShowTitle = true;
            this._TbBAN.MaxLength = 30;
            this._TbBAN.WikiKeyword = "Ban-Assignment";
            this._TbBAN.Title = "BAN :";
            this._RadAjaxPanel.Controls.Add(this._TbBAN);
 
            this._btnCopyToSelect.ID = "BtCopyToSelected";
            this._btnCopyToSelect.Text = "Copy To Selected";
            this._btnCopyToSelect.ToolTip = "This will save the BAN above to all selected items.";
            this._btnCopyToSelect.CssClass = "GxButtonBlue";
            this._btnCopyToSelect.Click += new EventHandler(BtnCopyToSelected_Click);               
            this._RadAjaxPanel.Controls.Add(this._btnCopyToSelect);                       
        }
 
        this._btnSaveSelected.ID = "BtSaveToSelected";
        this._btnSaveSelected.Text = "Save Selected";
        this._btnSaveSelected.CssClass = "GxButtonBlue";
        this._btnSaveSelected.Click += new EventHandler(BtSaveToSelected_Click);      
        this._RadAjaxPanel.Controls.Add(this._btnSaveSelected);
                    
        this.Controls.Add(this._RadAjaxPanel);
        this._btnCopyToSelect.OnClientClick = "OnClientClick('" + _RadGrid1.ClientID + "')";
        this._btnSaveSelected.OnClientClick = "OnClientClick('" + _RadGrid1.ClientID + "')";
        //  this._btnCopyToSelect.Attributes.Add("OnClick", "OnClientClick('" + _RadGrid1.ClientID +"');return true;");
        //this._btnSaveSelected.Attributes.Add("OnClick", "OnSaveToSelectedClick('" + _RadGrid1.ClientID + "');return false;");
    }
         
     
    private void BtnCopyToSelected_Click(object sender, EventArgs e)
    {           
            int[] productIds = null;
            int productId;
            System.Collections.Generic.List<int> listItems = new System.Collections.Generic.List<int>();         
            foreach (GridDataItem dataItem in this._RadGrid1.SelectedItems)
            {                                                
                productId = Convert.ToInt32(dataItem.GetDataKeyValue(this._PriceDealProductBanTable.PriceDealEntityProductItemIdColumn.ColumnName));
                listItems.Add(productId);                  
            }
        try
        {
            productIds = listItems.ToArray();
            if (!string.IsNullOrEmpty(this._TbBAN.Value))
            {
                foreach (int priceDealEntityProductId in productIds)
                {
                    new PriceDealEntityProductItem_UpdateBANById().ExecuteNonQuery(
                            priceDealEntityProductId
                            , this._TbBAN.Value
                            , SessionMatrix.Current.IFOPrincipal.UserId);
                }
            }
        }
        catch (Exception ex)
        {
            GlobalCrossing.Ucommand.Library.ErrorManager.LogCriticalError("AssignBanCtrl.CopyToSelected", System.Environment.MachineName, "", "", "80", ex.Message, "-3838383", ex);
        }
        //DataSource should be set to null else NeedDataSource() is not called!
        this._RadGrid1.DataSource = null;
        this._RadGrid1.Rebind();
        this._TbBAN.Text = "";
    }
 
    void BtSaveToSelected_Click(object sender, EventArgs e)
    {
        var xmlBuilder = new System.Text.StringBuilder();
        int productId;
        var banValue = String.Empty;
        var assetId = string.Empty;
        foreach (GridDataItem dataItem in this._RadGrid1.SelectedItems)
        {
            productId = Convert.ToInt32(dataItem.GetDataKeyValue(this._PriceDealProductBanTable.PriceDealEntityProductItemIdColumn.ColumnName));
            if (productId != null)
            {
                banValue = (dataItem.FindControl("BillingAccountNumber") as RadTextBox).Text;                       
                if (this._IsSupplementOrChangeQuote)
                {
                    assetId = (dataItem.FindControl("AssetServiceId") as RadTextBox).Text;
                }
            }
            xmlBuilder.AppendFormat("<PriceDealEntityProductItem ID=\"{0}\" BillingAccountNumber=\"{1}\" AssetServiceId=\"{2}\" />{3}",
                productId,
                banValue,
                assetId,
                Environment.NewLine);
        }          
 
        try
        {
            var selectionsToSaveXml = xmlBuilder.ToString();
 
            if (!string.IsNullOrEmpty(selectionsToSaveXml))
            {
                selectionsToSaveXml = string.Format("<PriceDealEntityProductItems>{0}{1}{0}</PriceDealEntityProductItems>",
                    Environment.NewLine,
                    selectionsToSaveXml);
 
                new PriceDealEntityProductItem_UpdateExitFieldsXml().ExecuteNonQuery(selectionsToSaveXml, SessionMatrix.Current.IFOPrincipal.UserId);
            }
        }
        catch (Exception ex)
        {
            GlobalCrossing.Ucommand.Library.ErrorManager.LogCriticalError("AssignBanCtrl.SaveSelected", Environment.MachineName, "", "", "80", ex.Message, "-3838383", ex);
        }
        //DataSource should be set to null else NeedDataSource() is not called!
        this._RadGrid1.DataSource = null;
        this._RadGrid1.Rebind();
    }         
 
 
 #endregion
    void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        try
        {
            this._PriceDealProductBanTable = new PriceDealEntityProductItem_ListBANByDealId().ExecuteTypedDataTable(this._Proposal.PriceDealId);
        }
        catch (Exception){ }
        this._RadGrid1.DataSource = this._PriceDealProductBanTable;
    }
 
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(Page);
        if (ajaxManager!=null)
            ajaxManager.AjaxSettings.AddAjaxSetting(this._RadAjaxPanel, this._RadGrid1, this._RadLoadingPanel);   
    }   
}
Tags
Grid
Asked by
RB
Top achievements
Rank 1
Answers by
RB
Top achievements
Rank 1
Share this question
or