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

Insert button does not show

4 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RB
Top achievements
Rank 1
RB asked on 06 May 2014, 10:03 PM
In my radgrid I am using a template for the insert form. The followinf are th RadGrid properties I have implemented:

                this._RadGrid1.Skin = "WebBlue";
            this._RadGrid1.Width = Unit.Percentage(100);
            this._RadGrid1.GridLines = GridLines.None;
            
            this._RadGrid1.AutoGenerateColumns = false;
            this._RadGrid1.AllowSorting = true;
            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.ClientSettings.DataBinding.EnableCaching = true;
            this._RadGrid1.EnableLinqExpressions = false;
            this._RadGrid1.MasterTableView.NoMasterRecordsText = string.Format("There are no records");
            this._RadGrid1.MasterTableView.Width = Unit.Percentage(100);
            this._RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
            this._RadGrid1.MasterTableView.DataKeyNames = new string[] { this._OrderTable.OrderIdColumn.ColumnName };
            this._RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = true;           
            this._RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
            this._RadGrid1.MasterTableView.CommandItemSettings.AddNewRecordText = "Add Order task";
            this._RadGrid1.MasterTableView.AllowAutomaticInserts = false;
            //this._RadGrid1.MasterTableView.EditFormSettings.UserControlName = "AddOrderTaskControl.ascx";
            this._RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template;
            this._RadGrid1.MasterTableView.EditFormSettings.FormTemplate = new InsertFormTemplate(this._OrderRequestId, this._SourceSystemTypeId, false);           
 
            this._RadGrid1.InsertCommand += _RadGrid1_InsertCommand;
            this._RadGrid1.ItemCommand += _RadGrid1_ItemCommand;
            this._RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;

ON click of Add New button, the template opens but it does not have a Insert/Cancel button.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 May 2014, 04:38 AM
Hi,

Please make sure that you have added the insert and cancel button to the form. Take a look at the below code snippet. Provide your InsertFormTemplate class code if this doesn't help.

C#:
protected void Page_Init(object source, System.EventArgs e)
{
   RadGrid1 = new RadGrid();
. . . .
   RadGrid1.AutoGenerateEditColumn = true;
   RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template;
   RadGrid1.MasterTableView.EditFormSettings.FormTemplate = new InsertFormTemplate();
. . . .
}
public class InsertFormTemplate : ITemplate
{
    Label lblName;
    TextBox txtName;
    Button btnInsert;
    Button btnCancel;
    public void InstantiateIn(System.Web.UI.Control container)
    {
        lblName = new Label();
        lblName.ID = "lblName";
        container.Controls.Add(lblName);
        lblName.Text = "Name";
        txtName = new TextBox();
        txtName.ID = "txtName";
        container.Controls.Add(txtName);
        btnInsert = new Button();
        btnInsert.ID = "btnInsert";
        btnInsert.Text = "Insert";
        btnInsert.CommandName = "PerformInsert";
        container.Controls.Add(btnInsert);
        btnCancel = new Button();
        btnCancel.ID = "btnCancel";
        btnCancel.Text = "Cancel";
        btnCancel.CommandName = "Cancel";
        container.Controls.Add(btnCancel);
    }
}

Thanks,
Princy
0
RB
Top achievements
Rank 1
answered on 07 May 2014, 04:15 PM
Thanks for the reply Princy. The template does not close after an Insert/Cancel.
public class InsertFormTemplate : IBindableTemplate
{
    SmartOrderRequest _smartOrderRequest;
    int _sourceSystemTypeId;
    bool _showDefaults;
    int _orderRequestId;
    GXButton btnInsert;
    GXButton btnCancel;
     
    OrderRequestTaskCreateCtrl _orderRequestTaskCreateCtrl;
    public InsertFormTemplate(int orderRequestId, int sourceSystemTypeId, bool showDefaults)
    {
        _orderRequestId = orderRequestId;     
        _sourceSystemTypeId = sourceSystemTypeId;
        _showDefaults = showDefaults;     
    }
    public void InstantiateIn(Control container)
    {
       
        if (this._orderRequestId > 0)
            this._smartOrderRequest = new SmartOrderRequest(this._orderRequestId);
 
        if (this._smartOrderRequest != null)
        {
            _orderRequestTaskCreateCtrl = new OrderRequestTaskCreateCtrl(this._smartOrderRequest, this._sourceSystemTypeId, false);           
            _orderRequestTaskCreateCtrl.ID = "_OrderRequestTaskAddCtrl";        
            //this._orderRequestTaskCreateCtrl.ExceptionSaved += _ExceptionOrderReqTaskAddCtrl_ExceptionSaved;
        }       
        container.Controls.Add(_orderRequestTaskCreateCtrl);
        btnInsert = new GXButton();
        btnInsert.ID = "btnInsert";
        btnInsert.Text = "Insert";       
        btnInsert.Click += new EventHandler(BtnSave_Click);
        container.Controls.Add(btnInsert);
 
        btnCancel = new GXButton();
        btnCancel.ID = "btnCancel";
        btnCancel.Text = "Cancel";       
        container.Controls.Add(btnCancel);
    }
 
    private void BtnSave_Click(object sender, EventArgs e)
    {
        _orderRequestTaskCreateCtrl.Save();       
    }
    public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
    {
        OrderedDictionary od = new OrderedDictionary();  
        return od;
    }
}

In the previous post I have already mentioned my RadGrid properties. AllowAutomaticInsert is also set to false. Should it automatically close the template after Insert/Cancel or do I have to handle it?
0
RB
Top achievements
Rank 1
answered on 07 May 2014, 08:49 PM
Can you also let me know how can I hide the "Add New Record" button after it had been clicked and the template opens.
0
Princy
Top achievements
Rank 2
answered on 08 May 2014, 05:11 AM
Hi,

You have created buttons for insert and cancel, since you haven't set the command name, you will have to close the Insert form manually and perform insertion in that button click event, else set command name so that it can handle the Insert and Cancel in the InsertCommand event.

C#:
btnInsert = new Button();
btnInsert.ID = "btnInsert";
btnInsert.Text = "Insert";
btnInsert.Click += new EventHandler(btnInsert_Click);
 
void btnInsert_Click(object sender, EventArgs e)
{
 //Code to insert
 RadGrid1.MasterTableView.IsItemInserted = false;
 RadGrid1.Rebind();
}
// or
btnInsert = new Button();
btnInsert.ID = "btnInsert";
btnInsert.Text = "Insert";
btnInsert.CommandName = "PerformInsert";
....
void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
    //Code for insert
}

To hide the AddNewRecord button after its click, please try the following:

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

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