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

Inser child item on ItemDataBound event.

2 Answers 76 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Valdas
Top achievements
Rank 1
Valdas asked on 03 Feb 2012, 11:16 PM
Hi,
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 = ""
            'dataItem.InsertChildItem()
        End If

<Columns>
                            <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">
                                <ItemTemplate>
                                    <telerik:RadButton ID="btnCancel" Text="Upload" runat="server" CausesValidation="False"
                                        CommandName="UploadFiles" CommandArgument='<%# Bind("Patient_Id") %>'>
                                        <Icon PrimaryIconUrl="~/Images/upload16X16.png" PrimaryIconLeft="5px" />
                                    </telerik:RadButton>
                                </ItemTemplate>
                            </telerik:TreeListTemplateColumn>
                            <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}" />
                        </Columns>

Thank you for the help.

2 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 08 Feb 2012, 02:09 PM
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,
Tsvetina
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Valdas
Top achievements
Rank 1
answered on 08 Feb 2012, 04:42 PM
Hi,
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.
Tags
TreeList
Asked by
Valdas
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Valdas
Top achievements
Rank 1
Share this question
or