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

Hidden autogenerated columns come back on postback

2 Answers 95 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Damien
Top achievements
Rank 1
Damien asked on 11 Feb 2013, 03:45 PM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Feb 2013, 05:14 AM
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
0
Damien
Top achievements
Rank 1
answered on 12 Feb 2013, 09:49 AM
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
Tags
TreeList
Asked by
Damien
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Damien
Top achievements
Rank 1
Share this question
or