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

Avoid Multiple Insert/Edit

7 Answers 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jens
Top achievements
Rank 1
Jens asked on 24 Apr 2008, 02:40 PM
Hi,

My RadGrid has three layers of nested grids. I'm using EditForms with templates throughout.
I want not more than one edit/insert form being shown in the whole grid at the same time. How can I achieve that?

I tried several ways, but the behaviour is never really how I want it. E.g. when the insert form is displayed in the the MasterTableView, it will stay open no matter which insert/edit button I click.

If an edit form is displayed in the MasterTableView, and I click any other insert or edit button, the form is not shown, but nonetheless the Item stays in edit mode.
Maybe I need to rebind the Grid at some point?

Does anybody know the best practise?

Thank for your help,
Jens

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Apr 2008, 04:54 AM
Hi Jens,

Have a look at the following help article.
Switching the Insert/Updade/Regular Modes

Thanks
Princy.
0
Jens
Top achievements
Rank 1
answered on 25 Apr 2008, 06:42 AM
Thank you, Princy,

I had read that article and tried it out.
BUT, when the insert form is open in the MasterTableView (!), and I click Edit in a DetailGrid (!), then

e.Item.OwnerTableView.IsItemInserted = false;

obviously doesn't help.

I'd have to write

((RadGrid)source).MasterTableView.IsItemInserted = false;

So I did, BUT the Insert Form in the MasterTableView still shows up (although it is set to false!).

0
Shinu
Top achievements
Rank 2
answered on 25 Apr 2008, 07:02 AM
Hi Jens,

Try setting AllowMultiRowEdit to false in the aspx as shown below.

ASPX:
<rad:radgrid id="RadGrid1" runat="server"   AllowMultiRowEdit="False"    > 


Thanks
Shinu
0
Jens
Top achievements
Rank 1
answered on 25 Apr 2008, 07:35 AM
Thank you, Shinu,

but AllowMultiRowEdit was already set to false.

Everythin works fine within ONE GridView, but not anymore, when there are several GridViews involved.

Could it be a binding issue? There is another effect makes me to think that:
I want the Edit button not to be shown, when the Edit form is opened. That's why I  do the following:


 protected void RadGrid1_ItemDataBound(object source, GridItemEventArgs e) 
        { 
            if (e.Item.IsInEditMode && e.Item is GridEditFormItem && e.Item.ItemIndex >= 0) 
            { 
                GridEditFormItem eeditItem = e.Item as GridEditFormItem; 
                TableCell editButtonCell = null
                switch (editItem.OwnerTableView.Name) 
                { 
                    case "UserGroupGridTableView": 
                        editButtonCell = editItem.ParentItem["EditUserGroupButtonColumn"]; 
                        break; 
                    case "UserGridTableView": 
                        editButtonCell = editItem.ParentItem["EditUserButtonColumn"]; 
                        break; 
                } 
                editButtonCell.Controls[0].Visible = false
            } 
        } 


That works fine, too. BUT consider following scenario:
- I click edit in the MasterGridView (!)
- Then, I click insert in a DetailGrid (!)

What happens, is: The edit form in the MasterGrid disappears, BUT the Edit button of that item doesn't reappear.

Any more ideas?


0
Johan
Top achievements
Rank 1
answered on 07 Nov 2012, 12:48 PM
Is there a option that does this AllowMultiRowInsert="False"

if you add multiple insert forms the validation between the forms clash

or how do you prevent multiple inserts in a grid with 1 detail table?
0
Maria Ilieva
Telerik team
answered on 12 Nov 2012, 02:56 PM
Hello Johan,

Check out the sample code below which shows how to close the insert form in MasterTable when the user clicks AddNewRecord button in DetailTable.
<MasterTableView Name="Master" runat="server" AutoGenerateColumns="true" DataKeyNames="EmployeeID"  
        CommandItemDisplay="Top">  
        <DetailTables>  
            <telerik:GridTableView Name="GridTableView1" runat="server" AutoGenerateColumns="true"  
                DataKeyNames="EmployeeID" CommandItemDisplay="Top" DataSourceID="SqlDataSource2">  
                <ParentTableRelation>  
                    <telerik:GridRelationFields DetailKeyField="EmployeeID" MasterKeyField="EmployeeID" />  
                </ParentTableRelation>  
                <Columns>  
                    <telerik:GridEditCommandColumn>  
                    </telerik:GridEditCommandColumn>  
                </Columns>  
            </telerik:GridTableView>  
        </DetailTables>  
        <Columns>  
            <telerik:GridEditCommandColumn UniqueName="EditColumn">  
            </telerik:GridEditCommandColumn>  
        </Columns>  
 </MasterTableView

C#:
int index;  
 int i = 0;  
 protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
 {  
     if (e.CommandName == "InitInsert" && e.Item.OwnerTableView.Name == "GridTableView1")  
     {  
         i = 1;   
         index=e.Item.OwnerTableView.ParentItem.ItemIndex;  
     }  
 }  
protected void RadGrid1_PreRender(object sender, EventArgs e)  
 {  
     if (RadGrid1.MasterTableView.IsItemInserted)  
     {  
         if (i == 1)  
         {  
             RadGrid1.MasterTableView.IsItemInserted = false;                 
             RadGrid1.MasterTableView.Rebind();  
             RadGrid1.MasterTableView.Items[index].Expanded = true;  
             (RadGrid1.MasterTableView.Items[index] as GridDataItem).ChildItem.NestedTableViews[0].IsItemInserted = true;  
             (RadGrid1.MasterTableView.Items[index] as GridDataItem).ChildItem.NestedTableViews[0].Rebind();  
         }  
     }  
 }  

I hope this helps.

Greetings,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Johan
Top achievements
Rank 1
answered on 13 Nov 2012, 04:44 AM
Thank you Maria Ilieva for your reply !!

Some one replied on this thread giving a solution that worked and the code is already deployed, so I am not going to change it now.

http://www.telerik.com/community/forums/aspnet-ajax/grid/only-allow-one-edit-or-insert-in-a-radgrid.aspx
Tags
Grid
Asked by
Jens
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jens
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Johan
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or