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

Edit and Add Button column in NestedViewTemplate

3 Answers 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pavan
Top achievements
Rank 1
pavan asked on 23 Feb 2011, 08:53 AM

I'm using a hierarchical grid. My Radgrid contain NestedViewTemplate which contain Another Radgrid .Inner Radgrid contain some GridBoundColumn and  GridButtonColumn called EDIT.This Inner Grid use <EditFormSettings EditFormType="Template">.
Now when we click on Edit,it is not able to open Edit form template.Instead of this, All the rows inside the inner grid get disappear.

Please help me out here...Thanks in advance.

<telerik:RadGrid ID="Radgrid1"  Visible="true"  runat="server" EnableViewState="true" AllowPaging="false" AllowSorting="true"     AutoGenerateColumns="false" Skin="Vista" OnItemCommand="Radgrid1_ItemCommand" OnSortCommand="Radgrid1_SortCommand"    AllowAutomaticDeletes="true" AllowAutomaticInserts="false" AllowAutomaticUpdates="false">
    <MasterTableView Width="100%" Name="mastertableview" DataKeyNames="custemerid" >
        <NestedViewTemplate>                                  
           <telerik:RadGrid ID="Radgrid2" AllowAutomaticDeletes="true"" AllowAutomaticInserts="false"
                    AllowAutomaticUpdates="true" AllowSorting="true"   OnItemCommand="Radgrid2_ItemCommand">
                       <MasterTableView CommandItemDisplay="Top" DataKeyNames="orderID"    AutoGenerateColumns="false" EditMode="EditForms" InsertItemDisplay="Top">                                                                                                                                                                                                   <Columns>
                               <telerik:GridBoundColumn HeaderText=""                                                                                      </telerik:GridBoundColumn>
                       <telerik:GridTemplateColumn HeaderText="Order Name"  UniqueName="Order Name"
                               <ItemTemplate>   <asp:Label runat="server" ID="lblOrderName" Text='<%# AntiXss.HtmlEncode(Eval("OrederName").ToString())%>'></asp:Label>  </ItemTemplate>
   </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn HeaderText=""     
       </telerik:GridTemplateColumn>
        <telerik:GridButtonColumn HeaderText="Edit" CommandName="Edit" Text="Edit" ItemStyle-HorizontalAlign="Center"
                 ButtonType="ImageButton" UniqueName="EditCommandColumn" ImageUrl="~/OneViewImages/edit.png">
              </telerik:GridButtonColumn>
                <telerik:GridButtonColumn HeaderText="Delete" ButtonType="ImageButton" ConfirmText="Are you sure you want to delete this User?"      ConfirmDialogType="RadWindow" ConfirmTitle="Delete" CommandName="Delete" Text="Delete User"  UniqueName="DeleteColumn" >
     </telerik:GridButtonColumn>
   </Columns>
           <CommandItemSettings AddNewRecordText="Add New User" />
                                                                        <EditFormSettings EditFormType="Template">
                                                                            <FormStyle Font-Size="11px" />
                                                                            <FormTemplate>    Edit form is here   Along with two Image button as Save and Calcel mention below
<asp:ImageButton ID="btnUpdate" runat="server" ToolTip="Save" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'    />  
   <asp:ImageButton ID="btnCancel" runat="server" ToolTip="cancel" CausesValidation="False"              CommandName="Cancel" />
        </FormTemplate>
                </EditFormSettings>
        </MasterTableView>
           <ValidationSettings CommandsToValidate="PerformInsert,Update" ValidationGroup="ValidationGrp1" />
                                                                </telerik:RadGrid>                                                                                                   </NestedViewTemplate>
                                                <Columns>
                                                    <telerik:GridBoundColumn UniqueName="CustomerID" DataField="CustomerId" Visible="false"    ReadOnly="true">
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="CustomerName" UniqueName="CustomerName"  >
                                                       </telerik:GridBoundColumn>
                                                </Columns>
                                                <ExpandCollapseColumn Visible="True">
                                                </ExpandCollapseColumn>
                                    </MasterTableView>
                                        </telerik:RadGrid>
  
  
  
  
  
Code Behind:
  
 protected void Radgrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
                RadGrid grid = (source as RadGrid);
    if ((e.CommandName == RadGrid.InitInsertCommandName ||
    e.CommandName == RadGrid.EditCommandName ||
    e.CommandName == RadGrid.EditAllCommandName ||
    e.CommandName == RadGrid.EditSelectedCommandName)
    && insertMode )
    {
    grid.MasterTableView.ClearEditItems();
    e.Item.OwnerTableView.IsItemInserted = false;
    }
                if ((e.CommandName == "ExpandCollapse") && (!e.Item.Expanded))
                {
               // populate innergrid
                }
            }
  
  
  
protected void Radgrid2_ItemCommand(object source, GridCommandEventArgs e)
        {
              
    //Code for During Add,Edit can no happen and vice-versa
    bool editMode = e.Item.OwnerTableView.OwnerGrid.EditIndexes.Count > 0;
    bool insertMode = e.Item.OwnerTableView.IsItemInserted;
                RadGrid Radgrid2 = (source as RadGrid);
    if ((e.CommandName == RadGrid.InitInsertCommandName ||
    e.CommandName == RadGrid.EditCommandName ||
    e.CommandName == RadGrid.EditAllCommandName ||
    e.CommandName == RadGrid.EditSelectedCommandName)
    && (insertMode || editMode))    {
                    Radgrid2.MasterTableView.ClearEditItems();
    e.Item.OwnerTableView.IsItemInserted = false;   }
  
if (e.CommandName == "Delete")
    {if (e.Item is GridDataItem)
{   
                  //Delete the selected OrderId then bind the inner grid using 
      Radgrid2.Rebind();
    }
 if (e.CommandName == "Edit")
                 {
                    Radgrid2.MasterTableView.EditFormSettings.UserControlName = null;
                     Radgrid2.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template;
                     if (e.Item is GridDataItem)
                     {
                         GridDataItem item = (GridDataItem)e.Item;
                      //Some field to be loaded in edit mode                                                                        
                     }
            Radgrid2.Rebind();  
   }
  
if (e.CommandName == "Cancel")
{
      Radgrid2.Rebind();
         BindGrid(); // use to bind Outer grid
}
      if (e.CommandName == "Update")
         {
//some code
         }
  
if (e.CommandName == "InitInsert")
{   //Some code                           
                   Radgrid2.MasterTableView.ClearEditItems();
                   Radgrid2.MasterTableView.IsItemInserted = true;
                   Radgrid2.Rebind();
                    Radgrid1.Rebind();
}           }
                if (e.CommandName == "PerformInsert")
                {
//some code
               }
}
  
                  
            

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Feb 2011, 10:53 AM
Hello Pavan,

How do you populating the grid? The above code working fine at my end when I am using Advanced/Declarative databinding technique to populate the grid. I assume that you are using SimpleDataBinding technique (binding the grid in PageLoad event). If you are using any advanced feature in grid (like insert/delete/update operation), then a better approach is using "AdvancedData binding" using NeedDataSource event.
For more information about this can be available here.
Advanced Data-binding (using NeedDataSource event)

Hope this information helps,
-Shinu.
0
pavan
Top achievements
Rank 1
answered on 03 Mar 2011, 10:27 AM
thanks. It works

I have one another issue.Please help me here also.
In 3 level Gid hierarchy ,I want to expand  only 1st item on Page Load itself.
I tried below code:

 

 

protected void Page_PreRenderComplete(object sender, EventArgs e)

 

 

{

 

 

 

if (!Page.IsPostBack)

 

 

  Radgrid1.MasterTableView.Items[0].Expanded =

 

true;

 

}

but I got this error:
Script control Radgrid2 is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().

Here Radgrid2 is inside NestedViewTemplate of Radgrid1

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