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

How do I find RadGrid on ItemCommand Event of RadGrid that lies inside RadTreeList

1 Answer 157 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Ajay
Top achievements
Rank 2
Ajay asked on 25 Jun 2012, 12:03 PM
Hi Telerik,

I have RadGrid inside FormTemplate of RadTreeList. I have called an "ItemCommand" event on RadGrid that bascially deleted the uploaded files when user clicks the delete button within ItemTemplate of RadGrid. All its happening is good. But as soon as deletion gets done I'm trying to rebind the RadGrid , but its giving me EXCEPTION.

RadGrid element is null.

Can you help me ?

Below is my code:-
protected void FilesRadGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        foreach (TreeListDataItem item in KnowledgeBaseRadTreeList.Items)
        {
            RadGrid FilesRadGrid = item.FindControl("FilesRadGrid") as RadGrid;
 
            if (e.CommandName == "Del")
            {
                string[] values = e.CommandArgument.ToString().Split(':'); // ID:FilePath
                if (System.IO.File.Exists(Server.MapPath(values[1])))
                {
                    try
                    {
                        System.IO.File.Delete(Server.MapPath(values[1]));
                    }
                    catch { }
                }
                Glb_Entities.ExecuteSP(new object[] { "Usp_KnowledgeBase_Uploads_Delete"
                                            , "@KnowledgeBase_Uploads_ID", values[0]
                                        });
                FilesRadGrid.DataBind();
            }
        }
 
 
    }

While my RadGrid lies in Form Template of RadTreeList as :-
 
<EditFormSettings EditFormType="Template" PopUpSettings-Width="100%">
                               <FormTemplate>
                                   <asp:Panel ID="DetailsPanel" runat="server" DefaultButton="SaveRadButton">
                                       <table border="0" cellpadding="0" cellspacing="5" class="innertable">
                                              <tr>
                                               <td>
                                                     
                                               </td>
                                               <td class="td82">
                                                   <telerik:RadGrid ID="FilesRadGrid" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
                                                       AllowSorting="True" AutoGenerateColumns="False" CellSpacing="0" DataSourceID="FilesSqlDataSource"
                                                       GridLines="None" Width="530px" Visible="false" OnItemCommand="FilesRadGrid_ItemCommand">
                                                       <MasterTableView DataKeyNames="KnowledgeBase_Uploads_ID" DataSourceID="FilesSqlDataSource">
                                                           <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                                                               <HeaderStyle Width="20px" />
                                                           </RowIndicatorColumn>
                                                           <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                                                               <HeaderStyle Width="20px" />
                                                           </ExpandCollapseColumn>
                                                           <Columns>
                                                               <telerik:GridBoundColumn DataField="FileName" FilterControlAltText="Filter FileName column"
                                                                   HeaderText="File Name" SortExpression="FileName" UniqueName="FileName" FilterControlWidth="80%">
                                                                   <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                                   <ItemStyle HorizontalAlign="Left" Font-Size="11px" Font-Names="Arial" VerticalAlign="Middle" />
                                                               </telerik:GridBoundColumn>
                                                               <telerik:GridTemplateColumn HeaderText="Action" AllowFiltering="false">
                                                                   <ItemTemplate>
                                                                       <asp:ImageButton ID="DeleteImageButton" runat="server" ToolTip="Delete" CommandName="Del"
                                                                           ImageUrl="~/App_Themes/ELPISCMS/images/delete.png" OnClientClick="if (!confirm('Are you sure, you want to delete this record?')) {return false;}"
                                                                           CommandArgument='<%# Eval("KnowledgeBase_Uploads_ID") +":"+ Eval("KnowledgeBase_Uploads_ID") %>' />
                                                                   </ItemTemplate>
                                                                   <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                                                                   <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                                                               </telerik:GridTemplateColumn>
                                                           </Columns>
                                                           <EditFormSettings>
                                                               <EditColumn FilterControlAltText="Filter EditCommandColumn column" />
                                                           </EditFormSettings>
                                                       </MasterTableView>
                                                       <FilterMenu EnableImageSprites="False" />
                                                       <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" />
                                                   </telerik:RadGrid>
                                                   <asp:SqlDataSource ID="FilesSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:elpis_cmsConnectionString %>"
                                                       SelectCommand="Usp_KnowledgeBase_Uploads_Select" SelectCommandType="StoredProcedure">
                                                       <SelectParameters>
                                                           <asp:ControlParameter ConvertEmptyStringToNull="true" ControlID="KnowledgeBaseIDHiddenField"
                                                               DbType="Int32" Name="KnowledgeBase_ID" PropertyName="Value" />
                                                       </SelectParameters>
                                                   </asp:SqlDataSource>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td class="td18">
                                                   Status :
                                               </td>
                                               <td class="td82">
                                                   <asp:RadioButton ID="ActiveRadioButton" runat="server" CssClass="radiobutton" Checked="true"
                                                       GroupName="ActiveInactive" />Active
                                                   <asp:RadioButton ID="InactiveRadioButton" runat="server" CssClass="radiobutton" GroupName="ActiveInactive" />Inactive
                                               </td>
                                           </tr>
                                           <tr>
                                               <td>
                                                     
                                               </td>
                                               <td class="td82">
                                                   <telerik:RadButton ID="SaveRadButton" runat="server" Text='<%# (Container is TreeListEditFormInsertItem) ? "Save" : "Update" %>'
                                                       CausesValidation="true" CommandName='<%# (Container is TreeListEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                                       ValidationGroup="KnowledgeBaseValidationGroup" Width="80px">
                                                       <Icon PrimaryIconUrl="~/App_Themes/ELPISCMS/images/save2.png" PrimaryIconLeft="5"
                                                           PrimaryIconTop="3" />
                                                   </telerik:RadButton>
                                                   <telerik:RadButton ID="CancelRadButton" runat="server" Text="Cancel" CommandName="Cancel"
                                                       CausesValidation="false" Width="80px">
                                                       <Icon PrimaryIconUrl="~/App_Themes/ELPISCMS/images/cancel2.png" PrimaryIconLeft="5"
                                                           PrimaryIconTop="3" />
                                                   </telerik:RadButton>
                                               </td>
                                           </tr>
                                       </table>
                                   </asp:Panel>
                               </FormTemplate>
                           </EditFormSettings>

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2012, 09:05 AM
Hello Ajay,

Try accessing the radgrid using the following code.
C#:
protected void grid1_ItemCommand(object sender, GridCommandEventArgs e)
{
  foreach (TreeListEditFormItem item in RadTreeList1.EditItems)
  {
     RadGrid FilesRadGrid = item.FindControl("FilesRadGrid") as RadGrid;
  }
}

Thanks,
Shinu.
Tags
TreeList
Asked by
Ajay
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or