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

how to the tree list expand on click of checkbox column

1 Answer 185 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
sravanthi
Top achievements
Rank 1
sravanthi asked on 30 Aug 2011, 02:39 AM
Hi Every one,

I am trying to expand the list of the rows on click of the checkbox which is in the TreelistTempelatecolumn.I am not able to maintain the state of the variables.Can anyone help me please.

This is what I am doing
<telerik:RadPanelItem Value="CandidateInformation" runat="server">
                        <ItemTemplate>
                            <telerik:RadTreeList ID="rtlSpecsGroup" Width="40%" runat="server" DataSourceID="sdsTreeView"
                                    ParentDataKeyNames="PARENTID" AllowSorting="true" DataKeyNames="CATGROUPID" AllowMultiItemSelection="false"
                                 AutoGenerateColumns="false" OnItemDataBound="OnItemDataBound_rtlSpecsGroup" >
                                <Columns>
                                    
                                    <telerik:TreeListTemplateColumn UniqueName="chkTempelatecolumn" DataField="CATGROUPID" ItemStyle-Width="30px" HeaderStyle-Width="30px">
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkGroups" runat="server" AutoPostBack="True" OnCheckedChanged="OnCheckedChanged_chkGroups"/>
                                        </ItemTemplate>
                                    </telerik:TreeListTemplateColumn>
                                   
                                    <telerik:TreeListBoundColumn UniqueName="NAME" HeaderText="Experience" DataField="NAME" ReadOnly="true"></telerik:TreeListBoundColumn>
                                    <telerik:TreeListTemplateColumn UniqueName="rblTempelatecolumn" HeaderText="YearsOfExperience">
                                        <ItemTemplate>
                                            <asp:RadioButtonList ID="rblYearsOfExp" runat="server" Enabled="false" RepeatDirection="Horizontal" RepeatLayout="Flow">
                                                <asp:ListItem Text="0-5" Value="1"></asp:ListItem>
                                                <asp:ListItem Text="6-10" Value="2"></asp:ListItem>
                                                <asp:ListItem Text="11-15" Value="3"></asp:ListItem>
                                                <asp:ListItem Text="16-20" Value="4"></asp:ListItem>
                                                <asp:ListItem Text="20+" Value="5"></asp:ListItem>
                                            </asp:RadioButtonList>
                                        </ItemTemplate>
                                    </telerik:TreeListTemplateColumn>
                                    <telerik:TreeListBoundColumn UniqueName="CATGROUPID" DataField="CATGROUPID" Visible="false" ReadOnly="true"></telerik:TreeListBoundColumn>
                                </Columns>
                            </telerik:RadTreeList>
                            <telerik:RadButton ID="rbtnCINext" runat="server" Text="Next>>" OnClick="rbtnCINext_OnClick">
                            </telerik:RadButton>
                            
                        </ItemTemplate>
                    </telerik:RadPanelItem>
on the code side this is what i am doing

    protected void OnCheckedChanged_chkGroups(object sender, EventArgs e)
    {
        RadPanelItem CandidateInformation = rpbMainInfo.FindItemByValue("CandidateInformation");
        RadTreeList rtlSpecsGroup = (RadTreeList)CandidateInformation.FindControl("rtlSpecsGroup");
        ((sender as CheckBox).NamingContainer as TreeListDataItem).Selected = (sender as CheckBox).Checked;
            foreach (TreeListDataItem tlTreeName in rtlSpecsGroup.Items)
            {
                string ParentId = tlTreeName["CATGROUPID"].Text;
                RadioButtonList rbtnlist = (RadioButtonList)tlTreeName.FindControl("rblYearsOfExp");
                if ((sender as CheckBox).Checked == true)
                {
                    if (tlTreeName.Selected == true)
                    {
                        if (ParentId == "1" || ParentId == "2" || ParentId == "3" || ParentId == "4")
                        {
                            tlTreeName.Expanded = true;
                          
                        }
                        
                    }
                   
                }
              
            }   
        
    }
what I am doing is On click of the check box I am trying to expand the parent item and also make the row selected.this part is working but the checkbox which I checked doesn't maintain.It returns the selected column with unchecked check box column.Itried with different styles but did not work out for me .Please let me know the best solution for the above problem

Thanks InAdvance,
Sravz

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 01 Sep 2011, 12:21 PM
Hello Sravanthi,

This is because RadTreeList needs to rebind on expand/collapse. Rebinding recreates all the items and the controls inside. Hence, any control that gets recreated inside treelist items is in its initial state. This is why your CheckBoxes all default to their non-checked state. To preserve their checked state after databinding, you need to save each CheckBox's Checked property value to some variable on your page and then restore the Checked state after rebinding inside the ItemDataBound treelist event.

Greetings,
Veli
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
TreeList
Asked by
sravanthi
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or