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

Cancel the insert of a DetailsView

1 Answer 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 12 Jul 2009, 04:05 PM
Here's the scenario...

I have a RadGrid (i.e. "rgPermissions") that has a DetailsView and is set to Inline edit mode.  I only want one row expanded at a time, so I wrote the following:

        protected void rgPermissions_ItemCommand(object sender, GridCommandEventArgs e)  
        {  
            if (e.CommandName.Equals("ExpandCollapse"))  
            {  
                if (Session["curExpanded"] != null)  
                {  
                    rgPermissions.MasterTableView.Items[Convert.ToInt32(Session["curExpanded"])].Expanded = false;  
 
                    if (e.Item.ItemIndex == Convert.ToInt32(Session["curExpanded"]))  
                    {  
                        e.Canceled = true;  
                        Session.Remove("curExpanded");  
                    }  
                    else 
                        Session["curExpanded"] = e.Item.ItemIndex;  
                }  
                else 
                {  
                    Session["curExpanded"] = e.Item.ItemIndex;  
                }  
            }  
            else if (e.CommandName.Equals("RebindGrid"))  
            {  
                Session.Remove("curExpanded");  
            }  
        } 

This works fine.

However, let's say I expand row 1 and click "Add New" in the details view.  Of course, the edit form in the details view displays on the first line.  Now, if I expand row 2 in the RadGrid, row 1's details view collapses and row 2's expands.  Finally, if I expand row 1 again, row 1's details view expands and row 2's collapses accordingly, BUT row 1's details view is STILL in InsertMode.

How do I manually cancel the insert mode of the details view?  I exhausted every way I know.

Thanks.
Joshua

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Jul 2009, 06:15 AM
Hi Joshua,

Give a try withe following code snippet to close the Insert form of the Detail table.

CS:
 
 protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName.Equals("ExpandCollapse")) 
        { 
             GridDataItem item=(GridDataItem)e.Item; 
            GridTableView childTable = (GridTableView)item.ChildItem.NestedTableViews[0]; 
            childTable.IsItemInserted = false
        } 
         
    } 


Thanks
Shinu
Tags
Grid
Asked by
Joshua
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or