Only allow one edit or insert in a RadGrid?

9 posts, 0 answers
  1. Chris
    Chris avatar
    2 posts
    Member since:
    Jul 2010

    Posted 22 Jul 2010 Link to this post

    I'm using the Telerik rad grid and I'm allow the user to enter data directly to the grid.

    I am using the "EditForms" edit mode and I also allow inserts using the same.

    If the user edits a row, then I don't want to allow any other edits or inserts until the current one is complete or cancelled.

    I'm totally new to Radgrids and I've recently been working in MVC... so any help would be great!

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Jul 2010 Link to this post

    Hello,


    Use the following code snippet in order hide editform when insert form is showing and vice versa.

    C#:
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
        if (e.CommandName == RadGrid.EditCommandName) 
        
            RadGrid1.MasterTableView.IsItemInserted = false
        
        if (e.CommandName == RadGrid.InitInsertCommandName) 
        
            RadGrid1.MasterTableView.ClearEditItems(); 
        
    }


    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chris
    Chris avatar
    2 posts
    Member since:
    Jul 2010

    Posted 23 Jul 2010 Link to this post

    Perfect. Thanks! :)
  5. Johan
    Johan avatar
    4 posts
    Member since:
    Nov 2012

    Posted 07 Nov 2012 Link to this post

    Thanks! 
    But this only works between edit and inserts,

    How can you allow only one insert at a time using a detail table?
  6. Greg
    Greg avatar
    7 posts
    Member since:
    Nov 2011

    Posted 08 Nov 2012 Link to this post

    I have the same question, I'm looking for the solution when using "inplace" editing also.
    Thanks!
  7. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 08 Nov 2012 Link to this post

    Hi,

    See this below works?. This solution was provided by Princy some years ago.

    Thanks
    gc_0620

    ______

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
           RadGrid grid = (source as RadGrid);
     
            if (e.CommandName == RadGrid.InitInsertCommandName &&  e.Item.OwnerTableView.Name == "Master")  
                // If insert mode, disallow edit
            {
                grid.MasterTableView.ClearEditItems();
            }
            if (e.CommandName == RadGrid.EditCommandName && e.Item.OwnerTableView.Name == "Master") // If edit mode, disallow insert
            {
                e.Item.OwnerTableView.IsItemInserted = false;
            }
            if (e.CommandName == RadGrid.ExpandCollapseCommandName) // Allow Expand/Collapse one row at a time
            {
                foreach (GridItem item in e.Item.OwnerTableView.Items)
                {
                    if (item.Expanded && item != e.Item)
                    {
                        item.Expanded = false;
                    }
                }
            }
    }

     

  8. gc_0620
    gc_0620 avatar
    225 posts
    Member since:
    Feb 2008

    Posted 08 Nov 2012 Link to this post

    Hi. Please try this for Detail Table.

    Thanks
    gc_0620

    ==============

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            RadGrid grid = (source as RadGrid);
     
            if (e.CommandName == RadGrid.InitInsertCommandName && e.Item.OwnerTableView.Name == "Detail")
            // If insert mode, disallow edit
            {
                e.Item.OwnerTableView.ClearEditItems();
            }
     
            if (e.CommandName == RadGrid.EditCommandName && e.Item.OwnerTableView.Name == "Detail") // If edit mode, disallow insert
            {
                e.Item.OwnerTableView.IsItemInserted = false;
            }
     
            if (e.CommandName == RadGrid.ExpandCollapseCommandName) // Allow Expand/Collapse one row at a time in Master Table
            {
                foreach (GridItem item in e.Item.OwnerTableView.Items)
                {
                    if (item.Expanded && item != e.Item)
                    {
                        item.Expanded = false;
                    }
                }
            }
        }

  9. Johan
    Johan avatar
    4 posts
    Member since:
    Nov 2012

    Posted 08 Nov 2012 Link to this post

    This is perfect thank you!!!!!!
  10. Greg
    Greg avatar
    7 posts
    Member since:
    Nov 2011

    Posted 12 Nov 2012 Link to this post

    This works great for my solution, thanks!!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017