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

Can't set to edit mode automatically in hierarchical grid

9 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paweł
Top achievements
Rank 1
Paweł asked on 13 Sep 2010, 06:21 PM
Hello, I'm using the newest version of RadControls for ASP.NET, and I've got a problem with launching the edit mode for RadGrid - it works like a charm for one instance of RadGrid, but for another - which is hierarchical - it doesn't. I am able to set edit mode manually - by EditColumn only.

My hierarchical grid looks is created in following way:

<telerik:RadGrid runat="server"
    ID="Grid"
    EnableAJAX="True"
    AllowMultiRowEdit = "True"
    EditMode="InPlace"
    OnItemDataBound="Grid_ItemDataBound"
    OnDetailTableDataBind="Grid_DetailTableDataBind"
    OnPreRender="Grid_PreRender"
    OnUpdateCommand="Grid_ItemUpdate"
    OnItemCreated="Grid_ItemCreated"
    DataSourceID="SqlDataSource1"
    AutoGenerateColumns="false">
      
    <MasterTableView DataKeyNames="MASTER_ID" >
     
     <DetailTables>
                            <telerik:GridTableView                           
                             EditMode="InPlace"
                            Name="Child" AutoGenerateColumns="False" Width="100%"
                              DataKeyNames="CHILD_ID" runat="server">
 
                                <Columns>                                  
                                 <telerik:GridEditCommandColumn /> 
                                   
                                <telerik:GridBoundColumn  DataField="CHILD_ID" HeaderText="CHILD_ID" ReadOnly="True"
                   SortExpression="CHILD_ID" UniqueName="CHILD_ID">
                                </telerik:GridBoundColumn>       
                                 
                                    
                                <telerik:GridBoundColumn  DataField="CHILD_Text" HeaderText="CHILD_Text" ReadOnly="False"
                   SortExpression="CHILD_Text" UniqueName="CHILD_Text">
                                </telerik:GridBoundColumn>                        
 
                   
                                </Columns>
                                </telerik:GridTableView>
                                 
    </DetailTables>                          
     
    <Columns>   
 
    <telerik:GridBoundColumn  DataField="CHILD_ID" HeaderText="CHILD_ID" ReadOnly="True"
                   SortExpression="CHILD_ID" UniqueName="CHILD_ID">
                                </telerik:GridBoundColumn>
                                 
    <telerik:GridBoundColumn  DataField="MASTER_ID" HeaderText="MASTER_ID" ReadOnly="True"
                   SortExpression="MASTER_ID" UniqueName="MASTER_ID">
                                </telerik:GridBoundColumn>     
                
                           
    </Columns>   
     
    </MasterTableView>
    
    </telerik:RadGrid>

And function, which is trying to turn on edit mode, looks like:

private void Grid_PreRender(object sender, System.EventArgs e)
{
 
if (!IsPostBack)
{
 
 foreach(GridItem item in Grid.MasterTableView.Items)
 {
  if (item is GridEditableItem)
  {
   GridEditableItem editableItem= item as GridDataItem;
   editableItem.Edit = true;
  }
 }
 Grid.Rebind();
}
 
}

Any help would be appreciated.

9 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Sep 2010, 07:38 AM
Hello Pawel,

Try the following code snippet to open the Detail table items in edit mode.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
          foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                GridTableView tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
                foreach (GridItem childItem in tableView.Items)
                {
                    if (childItem is GridEditableItem)
                    {
 
                        GridEditableItem editableItem = childItem as GridDataItem;
                        editableItem.Edit = true;
                    }
                }
                tableView.Rebind();
            }
         }
    }

Thanks,
Princy.
0
Paweł
Top achievements
Rank 1
answered on 14 Sep 2010, 04:49 PM
Thanks,

Actually, it didn't worked - I've now got an error:

"Collection was modified; enumeration operation may not execute.   at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext() "

at line:

foreach (GridItem childItem in tableView.Items)


Any ideas?
0
Iana Tsolova
Telerik team
answered on 20 Sep 2010, 09:26 AM
Hi Paweł,

Could you please specify what is the hierarchy load mode you are using? Try changing it to Client and let us know how it goes.

Best wishes,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paweł
Top achievements
Rank 1
answered on 21 Sep 2010, 11:47 PM
Hi,

I've been using a ServerBind, so it was wrong; thanks for the tip.

Unfortunatelly, it doesn't worked too - now I've got javascript error in browser, when I try to load hierarchy grid:

Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<HTML dir="ltr">
<H'.

0
Iana Tsolova
Telerik team
answered on 24 Sep 2010, 09:25 AM
Hello Paweł,

I am not able to determine what is the exact cause of the error based on the provided information.
To be able to investigate the issue further, I suggest that you open a formal support ticket and send me a runnable sample there.

Best wishes,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Daniel
Top achievements
Rank 2
answered on 09 Jun 2011, 09:36 PM
This code snippet works for me.

However when I have a three level hierarchy grid it does not put the third level into edit mode.

How can I accomplish this?

Daniel Honig
0
Shinu
Top achievements
Rank 2
answered on 10 Jun 2011, 05:27 AM
Hello Daniel,

Give a try with the following code snippet to put the third level into edit mode.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                GridTableView second_tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
                foreach (GridItem childItem in second_tableView.Items)
                {
                    GridTableView third_tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
                    foreach (GridItem grandchildItem in third_tableView.Items)
                    {
                        if (grandchildItem is GridEditableItem)
                        {
                            GridEditableItem editableItem = grandchildItem as GridDataItem;
                            editableItem.Edit = true;
                        }
                    }
                    third_tableView.Rebind();
                }
            }
        }
    }


-Shinu.
0
Daniel
Top achievements
Rank 2
answered on 10 Jun 2011, 02:39 PM

Hey Shinu,

Thanks for the response!

Nope got this error...

 

Server Error in '/' Application.

Collection was modified; enumeration operation may not execute.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

Source Error:

Line 118:                {
Line 119:                    GridTableView second_tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
Line 120: foreach(GridItem childItem in second_tableView.Items)Line 121:                    {
Line 122:                        GridTableView third_tableView = (GridTableView)item.ChildItem.NestedTableViews[0];


Regards,

Daniel
0
Daniel
Top achievements
Rank 2
answered on 13 Jun 2011, 09:01 PM
Shinu,

Do you have any Idea on how I can fix that error. I've played around with your snippet and still can't get rid of that enumeration error. Let me know if you have any advice.

Thanks,

Daniel
Tags
Grid
Asked by
Paweł
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Paweł
Top achievements
Rank 1
Iana Tsolova
Telerik team
Daniel
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or