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

[Solved] RadGrid Binding to a BindingList and adding items

2 Answers 207 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 18 Nov 2009, 02:45 PM
I am attempting to use a BindingList as my datasource as a temporary holding source until I put the data into my SQL database.  Displaying the data works just fine, the problem I am having is actually adding/inserting data.  Here is the flow:

1. I create 10 records on page load, they display fine, the DataSource is assigned in the NeedDataSource event.
2. Using an ASP.NET button, I invoke the RadGrid.MasterTableView.InsertItem() function which loads the default insert template.
3. After putting in the data and clicking the Insert link, the InsertCommand event is fired and I create a new record and add it to my BindingList and call RadGrid.Rebind().
4. The data gets added but the insert template does not go away and if I click on cancel to get it to go away, the data is no longer in the grid.

How can I get the Insert Template to close after I insert an item using the BindingList?

Seth

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Nov 2009, 08:37 AM
Hello Seth,

Have you set the AllowAutomaticInserts property of the grid to true? If so, try setting it to false, since you are manually inserting records to your grid. If this doesnt help, then try adding the following line of code in the InsertCommand after insert operation is done:
c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "InsertCommand"
        { 
            // insert operation 
 
            RadGrid1.MasterTableView.IsItemInserted = false
            RadGrid1.Rebind() 
             
        } 
    } 

Thanks
Princy.
0
Seth
Top achievements
Rank 1
answered on 19 Nov 2009, 02:09 PM
Thanks, setting AllowAutomaticInserts to false did it.
Tags
Grid
Asked by
Seth
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Seth
Top achievements
Rank 1
Share this question
or