Hide a column in details view programatically

6 posts, 0 answers
  1. John
    John avatar
    37 posts
    Member since:
    Jun 2010

    Posted 07 May 2012 Link to this post

    for the example listed here http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/autogeneratedhierarchy/defaultcs.aspx

    I want to hide a column in child table from code behind .. for example if I wanted to hide the order_ID in the child view how would I do that from code behind when the grid has been created programtically.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 08 May 2012 Link to this post

    Hello,

    protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
        {
             
            e.DetailTableView.Columns.FindByUniqueName("YourColumnUniqueName").Visible = false;
        }


    Thanks,
    Jayesh Goyani

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John
    John avatar
    37 posts
    Member since:
    Jun 2010

    Posted 09 Oct 2012 Link to this post

    I am creating the grid from code behind programatically and when I try to put the code as listed, it gives me a column not found error.  When I check the number of columns using e.DetailTableView.Columns.count then I get a value of 0 and also e.DetailTableView.RenderColumns.Count
    has a value of 2 when there are clearly more columns in the details view


    Any thoughts on what I might be missing?
  5. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 11 Oct 2012 Link to this post

    Hello John,

    Please try the following approach:
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        HideColumnRecursive(RadGrid1.MasterTableView);
    }
    public void HideColumnRecursive(GridTableView tableView)
    {
        GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
        foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
        {
            foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
            {
                GridColumn column = nestedView.GetColumnSafe("OrderID") as GridColumn;
                if (column != null)
                {
                    column.Visible = false;
                }
                if (nestedView.HasDetailTables)
                {
                    HideColumnRecursive(nestedView);
                }
            }
        }
    }

    I hope this will prove helpful. Please give it a try and let me know about the result.

    All the best,
    Eyup
    the Telerik team
    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 their blog feed now.
  6. Madhav Joshi
    Madhav Joshi avatar
    19 posts
    Member since:
    Oct 2012

    Posted 19 Dec 2012 Link to this post

    Hi Eyup,
    I tried you approach and i couldnot get any Result as Expected :( . Please give an alternative for the same. Along with that i want to remove the Nested Gridviews's headers also.

    Thanks,
    Madhav Joshi
  7. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 24 Dec 2012 Link to this post

    Hi Madhav,

    I have created a sample RadGrid web site to demonstrate that the suggested approach works as expected. Please check out the attached application and let me know about the result.

    All the best,
    Eyup
    the Telerik team
    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 their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017