Hidden autogenerated columns come back on postback

3 posts, 0 answers
  1. Damien
    Damien avatar
    17 posts
    Member since:
    Dec 2012

    Posted 11 Feb 2013 Link to this post

    Hello,

    First step: I have a generic page with a tree list control which is by default not visible.
    On some conditions, I make it visible and bind it on a datatable, result of a stored procedure.
    The columns are all autogenerated, so the stored procedure returns at least a column named DataKey and one named ParentDataKey (as named in the tree list declaration).

    <telerik:RadTreeList runat="server" ID="RadTreeList1"
                                                         Skin="Telerik"
                                                         AutoGenerateColumns="true"
                                                         DataKeyNames="DataKey" ParentDataKeyNames="ParentDataKey"
                                                         AllowSorting="true"
                                                         ItemStyle-CssClass="RowStyle"
                                                         AlternatingItemStyle-CssClass="AlternatingRowStyle"
                                                         HeaderStyle-CssClass="HeaderStyle"
                                                         SelectedItemStyle-CssClass="SelectedRowStyle"
                                                         OnAutoGeneratedColumnCreated="RadTreeList1_OnColumnCreated"
                                                         Visible="false"
                                                         >
     
                                         <ClientSettings>
                                            <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                                            <Resizing AllowColumnResize="true" ResizeMode="NoScroll" />
                                         </ClientSettings>
     
                                    </telerik:RadTreeList>

    This works correctly.

    Second step: I don't want to display the identifers used as data key and as parent data key. So I add some code just after the binding to hide those column.

    // Bind data with tree list display control
    this.RadTreeList1.DataSource = myDataTable;
    this.RadTreeList1.DataBind();
     
    // Hide the DataKey and ParentDataKey columns
    foreach (var c in this.RadTreeList1.AutoGeneratedColumns)
    {
        if (c.UniqueName.Equals("DataKey") || c.UniqueName.Equals("ParentDataKey"))
        {
            c.Display = false;
        }
    }

    This works correctly.

    Third step (the problem arrives):
    The datatable, result of the stored procedure is saved in viewstate.
    In the page_load method, on postback, the datatable is get from viewstate and the tree list is bind on it.

    At this moment, I run the some code to hide the data key and parent data key columns, but it doesn't work.
    I checked on debug, in page_load the display property is well set to false for the two columns (I also tried the visible property)
    but the two columns are always visible.

    Someone has an idea to hide those columns ?

    Thanks by advance.

    Regards,
    Damien
















  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Feb 2013 Link to this post

    Hi,

    Try hiding the column in Prerender event as shown below.
    C#:
    protected void RadTreeList1_PreRender(object sender, EventArgs e)
    {
            foreach (var c in this.RadTreeList1.AutoGeneratedColumns)
            {
                if (c.UniqueName.Equals("DataKey") || c.UniqueName.Equals("ParentDataKey"))
                {
                    c.Display = false;
                }
            }
    }

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Damien
    Damien avatar
    17 posts
    Member since:
    Dec 2012

    Posted 12 Feb 2013 Link to this post

    Hello,

    Thank you Princy for your answer. I tried your solution and it works fine.

    For information, if someone uses this topic, I replaced the initial "foreach" by the direct access to the columns.
    this.RadTreeList1.GetColumn("DataKey").Display = false;
    this.RadTreeList1.GetColumn("ParentDataKey").Display = false;

    Regards,
    Damien
Back to Top