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

Hide AddNewRecordButton and table header

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RB
Top achievements
Rank 1
RB asked on 29 May 2014, 09:47 PM
On click of the AddNewRecordButton, i want to hide button and the table header. On click of the addNewrecord, i can successfully hide the delete button on each row but the addNewRecord button still is visible! Also how can I hide the header?

I have a grid as follows. Add new record is a template.
          this._RadGrid1.ID = "RadGrid1";
        this._RadGrid1.Skin = "WebBlue";
        this._RadGrid1.Width = Unit.Percentage(100);
        this._RadGrid1.GridLines = GridLines.None;
        this._RadGrid1.AllowSorting = true;
        this._RadGrid1.AllowFilteringByColumn = false;
        this._RadGrid1.ShowGroupPanel = false;
        this._RadGrid1.AutoGenerateColumns = false;
        this._RadGrid1.AutoGenerateDeleteColumn = false;
        this._RadGrid1.AllowPaging = false;
        this._RadGrid1.EnableLinqExpressions = false;
        this._RadGrid1.MasterTableView.NoMasterRecordsText = "There are no documents associated with this order / quote / proposal.";      
        this._RadGrid1.ClientSettings.Selecting.AllowRowSelect = false;
        this._RadGrid1.ClientSettings.EnableRowHoverStyle = true;
        this._RadGrid1.ClientSettings.EnablePostBackOnRowClick = false;
        this._RadGrid1.MasterTableView.DataKeyNames = new string[] { this._EntityDocumentumReferenceTable.EntityDocumentumReferenceIdColumn.ColumnName };           
 
        this._RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
        this._RadGrid1.ItemDataBound += RadGrid1_ItemDataBound;
        this._RadGrid1.ItemCommand += RadGrid1_ItemCommand;    
 
          if (ShowAdd)
        {
            this._RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = true;
            this._RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;               
            this._RadGrid1.MasterTableView.CommandItemSettings.AddNewRecordText = "Add Document";                          
            this._RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template;
            this._RadGrid1.MasterTableView.EditFormSettings.FormTemplate = new AddDocumentTemplate(this._EntityId,
                       this._EntityType,
                       this._QuoteId,
                       this.CustomerNumber,
                       this.CompanyId,
                       this.ProposalNumber,
                       this.CatalogProductId);
        }
The ItemDataBound is as follows:
         private void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {        
           if (e.Item is GridDataItem)
           {            
               //Access the Insert Form, disable delete when in insert mode
              if (e.Item is GridEditableItem && !e.Item.IsInEditMode && e.Item.OwnerTableView.IsItemInserted)
              {
                  this._RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;                  
                  GridEditableItem insertItem = (GridEditableItem)e.Item;
                  ImageButton btnDelete = (ImageButton)dataItem["DeleteColumn"].Controls[0];
                  btnDelete.Visible = false;
                  //this._RadGrid1.ClientSettings.Selecting.AllowRowSelect = false;
              }
           } 
       }

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 May 2014, 05:13 AM
Hi,

You can try the following code snippet to hide the AddNewRecordButton and Header on InsertForm open.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.InitInsertCommandName)
  {
    RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
    RadGrid1.ShowHeader = false;
  }
  else
  {
    RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = true;
    RadGrid1.ShowHeader = true;
  }       
}

Thanks,
Princy
Tags
Grid
Asked by
RB
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or