Find Control Edit Template

4 posts, 0 answers
  1. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 16 Dec 2011 Link to this post

    I have a TreeList with an Edit Form Template. How do I go about finding those controls when the edit form is opened? With the RadGrid I could find these controls by using the ItemDataBound event and checking if the item is in edit mode. Is there a similar way to do this with the TreeList control?

    Thanks.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Dec 2011 Link to this post

    Hello Wiliam,

    Try the following code.
    C#:
    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
    {
     if (e.Item is TreeListEditableItem && (e.Item as TreeListEditableItem).IsInEditMode)
     {
        TreeListEditableItem item = (TreeListEditableItem)e.Item; 
        Label lbl = (Label)item.FindControl("Label1");
     }
    }

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 19 Dec 2011 Link to this post

    I'm getting a NullReferenceException, it can't seem to find the control. Below is a code snippet:

    ASPX

    <telerik:RadTreeList ID="notificationsTree" runat="server" AutoGenerateColumns="false" AllowSorting="false" AllowPaging="false" OnNeedDataSource="notifications_needdata" DataKeyNames="ID" ParentDataKeyNames="PID" ShowTreeLines="false" EditMode="PopUp" OnLoad="notifications_OnLoad" OnItemDataBound="notificationTree_ItemDataBound">
               <Columns>
                   <telerik:TreeListEditCommandColumn ShowEditButton="false" AddRecordText="Add"/>
                   <telerik:TreeListBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID" Visible="false" />
                   <telerik:TreeListBoundColumn HeaderText="PID" DataField="PID" UniqueName="PID" Visible="false" />
                   <telerik:TreeListBoundColumn HeaderText="Name" DataField="Name" />
                   <telerik:TreeListBoundColumn HeaderText="Item" DataField="ItemsID" />
                   <telerik:TreeListBoundColumn HeaderText="Category" DataField="Category" />
                   <telerik:TreeListBoundColumn HeaderText="Location" DataField="Location" />
                   <telerik:TreeListEditCommandColumn ShowAddButton="false"  />
               </Columns>
               <EditFormSettings EditFormType="Template" PopUpSettings-Modal="true" InsertCaption="Add Notification" PopUpSettings-Height="200px" PopUpSettings-Width="520px">
                   <FormTemplate>
                       <table>
                           <tr>
                               <td>Name:</td>
                               <td><telerik:RadTextBox ID="editName" runat="server" EmptyMessage="Enter Name" /></td>
                               <td>Category:</td>
                               <td><telerik:RadComboBox ID="editCategory" runat="server" EmptyMessage="Type a Category" MarkFirstMatch="true" /></td>
                           </tr>
                           <tr>
                               <td>Item:</td>
                               <td><telerik:RadComboBox ID="editItem" runat="server" EmptyMessage="Type a PS#" MarkFirstMatch="true" /></td>
                               <td>Location:</td>
                               <td><asp:DropDownList ID="editLocation" runat="server" /></td>
                           </tr>
                           <tr>
                               <td>Repeat Interval:</td>
                               <td><telerik:RadTextBox ID="editInterval" runat="server" /></td>
                               <td>Max Repeat:</td>
                               <td><telerik:RadTextBox ID="editRepeat" runat="server" /></td>
                           </tr>
                           <tr>
                               <td>Send On Weekends:</td>
                               <td><asp:CheckBox ID="editWeekends" runat="server" /></td>
                               <td>Send On Holidays:</td>
                               <td><asp:CheckBox ID="editHolidays" runat="server" /></td>
                           </tr>
                           <tr>
                               <td colspan="4"><telerik:RadButton ID="editSubmit" runat="server" Text="Submit" /></td>
                           </tr>
                       </table>
                   </FormTemplate>
               </EditFormSettings>
     
           </telerik:RadTreeList>


    C#

    protected void notificationTree_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
            {
                if (e.Item is TreeListEditableItem && (e.Item as TreeListEditableItem).IsInEditMode)
                {
                    TreeListEditableItem item = (TreeListEditableItem)e.Item;
                    RadTextBox txt = (RadTextBox)item.FindControl("editName");
     
                    txt.Text = "Test22";
                }
            }

  5. William
    William  avatar
    72 posts
    Member since:
    Jun 2011

    Posted 19 Dec 2011 Link to this post

    Fixed the issue by adding the following line to the IF statement check:

    (e.Item.ItemType == TreeListItemType.EditFormItem)
Back to Top