treelist view state Continues with new databind

2 posts, 0 answers
  1. HelloWorld
    HelloWorld avatar
    14 posts
    Member since:
    Jun 2013

    Posted 05 Jun 2013 Link to this post

    I have Search pages using treelist for results.
    the user have results expanded already with new search after the user left some of results expanded with first search.

    whenever user dose search with new options in, SearachHandler fires and then databind() with new result.
    the some of result are already expanded as if attachments.

    thanks you for helps in advance.
    code-behind:
     protected void SearchHandler(object sender, CriteriaController criteriaController)
            {
                if (radTreeResults.Visible)
                {
                    if (DtGrid == null) DoSearch();

                    DataView dv = new DataView(DtGrid, "", "", DataViewRowState.CurrentRows);
                    //DataView dv = new DataView(DtGrid, "ParentID is null", "", DataViewRowState.CurrentRows);
                    radTreeResults.DataSource = dv;
                    radTreeResults.DataBind();
                } 
                else
                    radTreeResults.Visible = true;
            }
            
            protected void TreeListDataSourceNeeded(object sender, EventArgs e)
            {
                if (DtGrid == null) DoSearch();
                DataView dv = new DataView(DtGrid, "", "", DataViewRowState.CurrentRows);
                //DataView dv = new DataView(DtGrid, "ParentID is null", "", DataViewRowState.CurrentRows);
                radTreeResults.DataSource = dv;
            }

    in aspx

    <asp:Content ID="Content3" ContentPlaceHolderID="RightColumnContentPlaceHolder" runat="server">
        <div id="gridViewContainer" style="height: 100%;">
            <telerik:RadTreeList ID="radTreeResults" runat="server" ParentDataKeyNames="ParentID" Visible="False"
                DataKeyNames="StandardID" Skin="Office2010Silver"  Width="100%" Height="100%"
                AutoGenerateColumns="False" OnNeedDataSource="TreeListDataSourceNeeded" 
                OnItemCommand="radTreeResults_ItemCommand" OnItemDataBound="radTreeResults_ItemDataBound" ShowTreeLines="false">
                <ClientSettings Scrolling-AllowScroll="true" Scrolling-UseStaticHeaders="true">
                    <Resizing ResizeMode="AllowScroll" AllowColumnResize="true" EnableRealTimeResize="true" />
                    <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" ScrollHeight="560px" />
                    <ClientEvents OnTreeListCreated="TreeListCreated" />
                </ClientSettings>
                <Columns>
                    <telerik:TreeListSelectColumn HeaderStyle-Width="40px" UniqueName="SelectColumn">
                    </telerik:TreeListSelectColumn>
                    <telerik:TreeListTemplateColumn HeaderStyle-Width="120px" DataField="NameDisplayText"
                        UniqueName="NameDisplayText" HeaderText="Name" >
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkExpandAll" runat="server" CommandName="ExpandCollapse"
                                CommandArgument="ExpandAll" Text="+" Visible="true"></asp:LinkButton>
                            <asp:LinkButton ID="lnkCollapseAll" runat="server" CommandName="ExpandCollapse"
                                CommandArgument="CollapseAll" Text="-" Visible="false"></asp:LinkButton>
                            <asp:HyperLink ID="lnkStandardName" runat="server" Target="_blank" NavigateUrl='<%#"~/Record/StandardsPage.aspx?xID=" + Eval("EncryptedID") %>'
                                Visible="True" Style="color: Blue;" StandardID='<%# Eval("EncryptedID") %>' StandardName='<%# Eval("StandardName") %>' ><%# Eval("NameDisplayText")%></asp:HyperLink>                        
                        </ItemTemplate>
  2. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 10 Jun 2013 Link to this post

    Hi,

    Most probably the problem comes from the fact that you are calling the DataBind() method of RadTreeList while you are using NeedDataSource event. Calling this method will break the databinding of RadGrid.

    Try to modify your code as follows:

    protected void SearchHandler(object sender, CriteriaController criteriaController)
    {
        if (radTreeResults.Visible)
        {      
            radTreeResults.DataSource = null;      
            radTreeResults.Rebind();
        }
        else
            radTreeResults.Visible = true;
    }

    and you should not have problems.

    Regards,
    Andrey
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top