Insert in Grid without databinding

4 posts, 0 answers
  1. oVan
    oVan avatar
    35 posts
    Member since:
    Apr 2008

    Posted 25 Feb 2009 Link to this post

    Is it possible to programmatically set the grid in Insert mode without the current records from the datasource been rendered? I assume that for the insert operation to work I really must databind.

    I currently use this:
            RadGrid1.MasterTableView.InsertItem();
    to set the grid in insert mode.

    What I want to achieve is use the nice editing capabilities of the grid to insert new items on a dedicated page or perhaps in a popup. I do not want to see the other records at that time.

    Thanks for any help.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Feb 2009 Link to this post

    Hello Olivier,

    You could set the EditMode property of the MasterTableView as PopUp inorder to display a popup form while inserting. To hide the data rows of the grid when the grid is in Insert mode, you can refer to the following help document which explains on the same:
    Hiding all rows on insert and displaying the edit form only

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. oVan
    oVan avatar
    35 posts
    Member since:
    Apr 2008

    Posted 25 Feb 2009 Link to this post

    Thank you Princy, that looks like a working solution.

    Would it be more efficient to intercept the databinding before rows get added? If I have a big grid without paging this could take quite a few cycles.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Feb 2009 Link to this post

    Hi Olivier,

    A suggestion is to bind your grid with data in the NeedDataSource event and then on clicking the AddNewRecordButton, i.e., on InitInsertCommand, you can set the datasource of the Grid to an empty object array as shown below:
    cs:

     protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
        {  
           if (e.CommandName == RadGrid.InitInsertCommandName)  
            {  
                RadGrid1.DataSource = new string[] { };  
            }         
        } 

    Also you can use EditFormTemplate, so that the same insert form is displayed. Once the new record is inserted successfully, rebind the grid as shown below:
    cs:

     protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)  
        {  
            //code for inserting into the database  
            RadGrid1.Rebind();  
        } 

    Thanks
    Shinu.

Back to Top