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

[Solved] Using showInsertItem Property

1 Answer 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ahmad
Top achievements
Rank 1
ahmad asked on 30 Oct 2009, 04:05 PM

Hi All,

 I need to use showInsertItem property that switches the grid in insert mode and displays the insertion form when i click "Add New  Record" on RadGrid.
 I Created RadGrid Programmatically and assigned grid.ClientSettings.ClientEvents.OnCommand = "addnewrecord";
 Then i register RegisterClientScriptBlock for addnewrecord on Page_Prerender.
 This is my code:

    RadGrid grid;

    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable gridDataTable = new DataTable();
      

        grid = new RadGrid();
        grid.ID = "grid1";
       
        grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
        grid.MasterTableView.AllowAutomaticInserts = true;
        grid.MasterTableView.InsertItemDisplay = GridInsertItemDisplay.Bottom;

        GridBoundColumn col1 = new GridBoundColumn();
        col1.HeaderText = "col1";
        col1.DataField = "col1";
        GridBoundColumn col2 = new GridBoundColumn();
        col2.HeaderText = "col2";
        col2.DataField = "col2";
        grid.Columns.Add(col1);
        grid.Columns.Add(col2);

        grid.ClientSettings.ClientEvents.OnCommand = "addnewrecord";
       
        grid.DataSource = gridDataTable;
        grid.DataBind();
        Page.Form.Controls.Add(grid);
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        string clientd = grid.ClientID;
        string gridScript = "function addnewrecord(sender, args){var masterTable = $find('" + clientd + "').get_masterTableView();masterTable.showInsertItem();}";
        ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "mykey", gridScript, true);
    }

Now,When i click "Add New Record" i get this error:Out of stack space.

Any Help is really appreciated.

Regards,
Ahmad

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Nov 2009, 07:56 AM
Hi Ahmad ,

Please include the RadGrid creation within  IsPostBack as false. Otherwise, you will end up adding the same objects to the RadGrid multiple times.

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