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

Hide Filter Column at Runtime

0 Answers 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 16 Jul 2008, 10:49 PM
If you find yourself needing to hide a filter column at runtime with AutoGenerated columns - you might consider the following server side:

Once you reference the OnItemCreated method in the mark-up just determine the column name you want to hide. I hardcoded for this example but you could set it from a session or whatever your little heart desires.

First, get a reference to the e.Items.Controls collection.
It will have a ton of controls in there for me it was 80+ for e.Items.
Second, using reflection get a reference to the underlying Sytem Type. In this case we are looking at for the "GridTableCell" type string.
Third, get a reference to each set of controls under that type.
Iterate the second collection looking for a UniqueID containing your chosen column name. This is neccessary because the control's UniqueId contains the full clientId with all that ct100 crap (UniqueID.Contains(columnName)).
Last, just get a reference to the control at the appropriate index and turn it off.

Now, for all you performance minded individuals - yes the iterations will add to the ticks of the grid and yes reflection adds some weight too - I tested on a grid bound to 23,567 recs (server side - w/Linq DataSource) and saw no impact to normal performance. Paging, Sorting, Filtering all worked without impact.

Why, well you might use this method if you feel client side script is a waste of time and beneath you or if you prefer to manage state server side. Also, perhaps you are loading an image inside a tooltip and want to suspress filtering. BTW, I could not find a solution in the support forum.

I patiently wait for the backlash....

protected void RadGridItems_OnItemCreated(object sender, GridItemEventArgs e)
    {
        string columnName = "Items_ImageURI";

        ControlCollection cCol = (ControlCollection)e.Item.Controls;
        for (int x = 0; x < cCol.Count; x++)
        {
            Type curType = cCol[x].GetType();
            string undertype = curType.UnderlyingSystemType.Name;
            if (undertype == "GridTableCell")
            {
                ControlCollection z = (ControlCollection)cCol[x].Controls;
                for (int y = 0; y < z.Count; y++)
                {
                    if (z[y].UniqueID.Contains(columnName))
                    {
                        Control filterControl = (Control)z[y];
                        filterControl.Visible = false;
                    }
                }
            }
        }
    }

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Jay
Top achievements
Rank 1
Share this question
or