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

Putting DetailTables in edit mode

3 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 09 Aug 2011, 02:03 AM
Hi.

I'm using the method below to place all rows in edit mode...
for (int i = 0; i < RadGrid1.PageSize; i++)
{
    RadGrid1.EditIndexes.Add(i);
}
RadGrid1.Rebind();

It works fine but my RadGrid has three levels of parent child relationships and this only works on the first level. How do I get it to affect all levels? Thanks in advance.
<telerik:RadGrid ID="RadGrid1" runat="server" ShowStatusBar="True" DataSourceID="SqlDataSource1" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateDeleteColumn="false" AutoGenerateEditColumn="false" GridLines="None" ShowGroupPanel="True" AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowMultiRowEdit="true">
    <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default">
    </HeaderContextMenu>
    <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="EmissionFactorGroupID" AllowMultiColumnSorting="True" PageSize="10" CommandItemDisplay="Bottom" CommandItemSettings-AddNewRecordText=" Add New Emission Factor Group" CommandItemSettings-ShowAddNewRecordButton="true" CommandItemSettings-ShowExportToExcelButton="true" EditMode="InPlace" NoDetailRecordsText="No emission factor groups to display." EditFormSettings-EditColumn-CancelText="Cancel" EditFormSettings-EditColumn-ButtonType="ImageButton">
        <DetailTables>
            <telerik:GridTableView AllowMultiColumnSorting="true" DataKeyNames="EmissionFactorID" DataSourceID="SqlDataSource2" Width="100%" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="false" CommandItemDisplay="Bottom" CommandItemSettings-AddNewRecordText=" Add New Emission Factor" CommandItemSettings-ShowAddNewRecordButton="true" EditMode="InPlace" NoDetailRecordsText="No emission factors to display.">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="EmissionFactorGroupID" MasterKeyField="EmissionFactorGroupID" />
                </ParentTableRelation>
                <DetailTables>
                    <telerik:GridTableView AllowMultiColumnSorting="true" DataKeyNames="EmissionGasBreakdownID" DataSourceID="SqlDataSource3" Width="100%" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="false" CommandItemDisplay="Bottom" CommandItemSettings-AddNewRecordText=" Add New Gas" CommandItemSettings-ShowAddNewRecordButton="true" EditMode="InPlace" NoDetailRecordsText="No gases to display.">
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="EmissionFactorID" MasterKeyField="EmissionFactorID" />
                        </ParentTableRelation>
                        <Columns>
                            <telerik:GridBoundColumn Visible="false" ReadOnly="true" DataField="EmissionGasBreakdownID" DataType="System.Int32" SortExpression="EmissionGasBreakdownID" UniqueName="EmissionGasBreakdownID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn Visible="false" ReadOnly="true" DataField="EmissionFactorID" SortExpression="EmissionFactorID" UniqueName="EmissionFactorID" DataType="System.Int32">
                            </telerik:GridBoundColumn>
                            <telerik:GridDropDownColumn DropDownControlType="RadComboBox" DataType="System.Int32" DataField="GasID" HeaderText="Gas" SortExpression="GasID" UniqueName="GasID" DataSourceID="SqlDataSource4" ListTextField="GasName" ListValueField="EmissionGasID">
                            </telerik:GridDropDownColumn>
                            <telerik:GridBoundColumn DataField="Factor" DataType="System.Decimal" HeaderText="Factor" SortExpression="Factor" UniqueName="Factor" DataFormatString="{0:0.000000000000}">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="UOM" HeaderText="UOM" SortExpression="UOM" UniqueName="UOM">
                            </telerik:GridBoundColumn>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" EditText="Edit..." UpdateText="Save your changes..." CancelText="Cancel your changes..." InsertText=" Add new item..." />
                            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Are you sure you wish to delete this gas?" />
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn Visible="false" ReadOnly="true" DataField="EmissionFactorID" DataType="System.Int32" HeaderText="EmissionFactorID" SortExpression="EmissionFactorID" UniqueName="EmissionFactorID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Factor" DataType="System.Decimal" HeaderText="Factor" SortExpression="Factor" UniqueName="Factor" DataFormatString="{0:0.000000000000}">
                    </telerik:GridBoundColumn>
                    <telerik:GridDateTimeColumn DataField="EffectiveFrom" DataType="System.DateTime" HeaderText="Effective From" SortExpression="EffectiveFrom" UniqueName="EffectiveFrom">
                    </telerik:GridDateTimeColumn>
                    <telerik:GridDateTimeColumn DataField="EffectiveTo" DataType="System.DateTime" HeaderText="Effective To" SortExpression="EffectiveTo" UniqueName="EffectiveTo">
                    </telerik:GridDateTimeColumn>
                    <telerik:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Source" HeaderText="Source" SortExpression="Source" UniqueName="Source">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn Visible="false" ReadOnly="true" DataField="EmissionFactorGroupID" DataType="System.Int32" HeaderText="EmissionFactorGroupID" SortExpression="EmissionFactorGroupID" UniqueName="EmissionFactorGroupID">
                    </telerik:GridBoundColumn>
                    <telerik:GridNumericColumn DataField="IPCCTier" DataType="System.Byte" HeaderText="IPCC" SortExpression="IPCCTier" UniqueName="IPCCTier" HeaderStyle-Width="20px" ItemStyle-Width="20px" NumericType="Number">
                    </telerik:GridNumericColumn>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" EditText="Edit..." UpdateText="Save your changes..." CancelText="Cancel your changes..." InsertText=" Add new item..." />
                    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Are you sure you wish to delete this emission factor?" />
                </Columns>
                <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                <ExpandCollapseColumn Visible="True">
                </ExpandCollapseColumn>
            </telerik:GridTableView>
        </DetailTables>
        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
        <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn Visible="false" ReadOnly="true" DataField="EmissionFactorGroupID" DataType="System.Int32" HeaderText="EmissionFactorGroupID" SortExpression="EmissionFactorGroupID" UniqueName="EmissionFactorGroupID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="GroupName" HeaderText="Group Name" SortExpression="GroupName" UniqueName="GroupName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ResourceType" HeaderText="Resource Type" SortExpression="ResourceType" UniqueName="ResourceType">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ResourceName" HeaderText="Name" SortExpression="ResourceName" UniqueName="ResourceName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ResourceUOM" HeaderText="UOM" SortExpression="ResourceUOM" UniqueName="ResourceUOM">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Region" HeaderText="Region" SortExpression="Region" UniqueName="Region">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="OwnerTenantID" HeaderText="Owner Tenant ID" SortExpression="OwnerTenantID" UniqueName="OwnerTenantID" DataType="System.Int32" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn DataField="Shared" DataType="System.Boolean" HeaderText="Shared" SortExpression="Shared" UniqueName="Shared">
            </telerik:GridCheckBoxColumn>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" EditText="Edit..." UpdateText="Save your changes..." CancelText="Cancel your changes..." InsertText=" Add new item..." />
            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Are you sure you wish to delete this emission factor group?" />
        </Columns>
    </MasterTableView>
    <ClientSettings AllowDragToGroup="True">
    </ClientSettings>
</telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 09 Aug 2011, 05:12 AM
Hello Chrisl,

Try the following code snippet in PreRender event to put all the DetailTable items in edit mode.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
  {
    if (!IsPostBack)
      {
         foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
          {
             item.Expanded = true;
             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();
           }
       }
  }
Set AllowMultiRowEdit  property of RadGrid to "True" to enable multi-row editing.

Thanks,
Shinu.
0
Chris
Top achievements
Rank 1
answered on 10 Aug 2011, 05:05 AM
Thanks Shinu.

That made all the second level rows in edit mode but not the first and third level rows. If I filtered the results only some of the second level rows are in edit mode and others are not. And when I paged ithey all went to Non-edit.

What event command should I be executing this code in?

Thanks
Chris
0
Jayesh Goyani
Top achievements
Rank 2
answered on 10 Aug 2011, 05:37 AM
Hello,

Traversing detail tables/items in Telerik RadGrid

let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or