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

Custom 'AddNewRecord' Form

2 Answers 64 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, 07:39 PM
I have a RagGrid. On click of "Add New", I want a customized form. Is this possible?
I tried the following but did not work!
protected void _RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
       {
          if (e.CommandName == RadGrid.InitInsertCommandName)
          {
              e.Canceled = true;
              this._RadGrid1.EditIndexes.Clear();

              e.Item.OwnerTableView.EditFormSettings.UserControlName = "AddControl.ascx";
              e.Item.OwnerTableView.InsertItem();
          }          
      }

2 Answers, 1 is accepted

Sort by
0
RB
Top achievements
Rank 1
answered on 06 May 2014, 08:33 PM
I apologize, got this to work. Instead of an ascx file, can I have a panel here?
0
Princy
Top achievements
Rank 2
answered on 07 May 2014, 06:18 AM
Hi ,

I guess you want to have different forms during edit and insert mode. You can create a Template EditForm for the insert. Please take a look at the sample code snippet.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        e.Canceled = true;
        this.RadGrid1.EditIndexes.Clear();
        e.Item.OwnerTableView.EditFormSettings.EditFormType = GridEditFormType.Template;
        e.Item.OwnerTableView.EditFormSettings.FormTemplate = new InsertFormTemplate();
        e.Item.OwnerTableView.InsertItem();
    }     
}
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
Tags
Grid
Asked by
RB
Top achievements
Rank 1
Answers by
RB
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or