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

Insert in Grid without databinding

3 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
oVan
Top achievements
Rank 2
oVan asked on 25 Feb 2009, 04:10 PM
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.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Feb 2009, 05:20 AM
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.
0
oVan
Top achievements
Rank 2
answered on 26 Feb 2009, 05:40 AM
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.
0
Shinu
Top achievements
Rank 2
answered on 26 Feb 2009, 10:47 AM

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.

Tags
Grid
Asked by
oVan
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
oVan
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or