Inser child item on ItemDataBound event.

3 posts, 0 answers
  1. Valdas
    Valdas avatar
    3 posts
    Member since:
    Aug 2011

    Posted 03 Feb 2012 Link to this post

    I would like to Insert child item on ItemDataBound event.
    My code:
    If TypeOf e.Item Is TreeListDataItem Then
                Dim dataItem = DirectCast(e.Item, TreeListDataItem)
                If dataItem.HierarchyIndex.NestedLevel <> 0 Then
                    dataItem("InsertCommandColumn").Controls(0).Visible = False
                End If
                dataItem("FileName").Text = ""
                dataItem("VisitName").Text = ""
            End If

                                <telerik:TreeListEditCommandColumn UniqueName="InsertCommandColumn" ButtonType="ImageButton"
                                    HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center" InsertText="Create Subject" />
                                <telerik:TreeListTemplateColumn AllowSorting="false" ItemStyle-Width="140px" HeaderStyle-Width="140px">
                                        <telerik:RadButton ID="btnCancel" Text="Upload" runat="server" CausesValidation="False"
                                            CommandName="UploadFiles" CommandArgument='<%# Bind("Patient_Id") %>'>
                                            <Icon PrimaryIconUrl="~/Images/upload16X16.png" PrimaryIconLeft="5px" />
                                <telerik:TreeListBoundColumn DataField="ClientPatient_Id" HeaderText="Subject ID"
                                    ReadOnly="true" UniqueName="ClientPatientId" HeaderStyle-Width="60px" ForceExtractValue="Always" />
                                <telerik:TreeListBoundColumn DataField="FileName" HeaderText="File Name" UniqueName="FileName"
                                    HeaderStyle-Width="300px" />
                                <telerik:TreeListBoundColumn DataField="Visit_Name" HeaderText="Visit" UniqueName="VisitName"
                                    HeaderStyle-Width="60px" />
                                <telerik:TreeListBoundColumn DataField="CreationDate" HeaderText="Date Created" UniqueName="CreationDate"
                                    HeaderStyle-Width="60px" DataFormatString="{0:d}" />

    Thank you for the help.
  2. Tsvetina
    Tsvetina avatar
    2087 posts

    Posted 08 Feb 2012 Link to this post

    Hi Valdas,

    ItemDataBound is not a good place to fire commands from, plus with the current code that you posted, you may get an Out of memory exception as you call this method for all items on each binding and the insert operation leads to a rebind itself.
    Can you please elaborate on what is your general goal and we will give you some suggestions that use the recommended practices for working with RadTreeList?

    All the best,
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Valdas
    Valdas avatar
    3 posts
    Member since:
    Aug 2011

    Posted 08 Feb 2012 Link to this post

    I was trying to build the list and add child elements on ItemDataBound.
    You are right, it's not a good practice. I resolved it by doing it on database level.
    I selected the parent element and did union on child selection.

    Thank you.
Back to Top