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

Hiding a Column in a RadGrid Detail Table (DataKeyName?)

1 Answer 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 27 Aug 2012, 03:20 PM
I have already trie a bunch of the solutions on the forum, but none of them seem to work.  I have a Grid control with a Detail Table contained therein.  No matter what I have tried, I cannot hide the column in the detail table.  Could it be due to the fact that the column is the data key?
<telerik:RadGrid ID="grdAgingReport" Skin="WebBlue" EnableEmbeddedSkins="false" ShowStatusBar="true" OnSortCommand="grdAgingReport_SortCommand" OnPageIndexChanged="grdAgingReport_PageIndexChanged"
Width="97%" OnPageSizeChanged="grdAgingReport_PageSizeChanged" OnItemCommand="grdAgingReport_ItemCommand" OnDetailTableDataBind="grdAgingReport_DetailTableDataBind" OnPreRender="grdAgingReport_PreRender"
 AllowSorting="True" PageSize="15" AllowPaging="True" AllowMultiRowSelection="false" runat="server" Gridlines="Both" CssClass="RadGrid_WebBlue"  HierarchyLoadMode="ServerOnDemand">
 <ExportSettings HideStructureColumns="true"/>
 <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="MainCategory">
    <PagerStyle Mode="NextPrevAndNumeric" />
    <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" ShowExportToWordButton="true" ShowExportToExcelButton="true" ShowExportToCsvButton="true" />
    <DetailTables>
        <telerik:GridTableView DataKeyNames="SecondaryCategory" Name="grdTimePeriods" Width="90%" HierarchyLoadMode="ServerBind"></telerik:GridTableView>
    </DetailTables>
 </MasterTableView>   
</telerik:RadGrid>

protected void grdAgingReport_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
    if (e.DetailTableView.Name == "grdTimePeriods")
    {
        GridDataItem _GridDataItem = (GridDataItem)e.DetailTableView.ParentItem;
        string sMainCategory = _GridDataItem.GetDataKeyValue("MainCategory").ToString();
        e.DetailTableView.DataSource = BuildSecondaryTable(sMainCategory);
 
        //foreach (GridColumn _Column in e.DetailTableView.Columns)
        //    if (_Column.UniqueName.ToUpper() == "SECONDARYCATEGORY")
        //    {
        //        _Column.Display = false;
        //        break;
        //    }
    }
}
 
protected void grdAgingReport_PreRender(object source, EventArgs e)
{
    foreach (GridColumn _Column in grdAgingReport.MasterTableView.AutoGeneratedColumns)
    {
        switch (_Column.UniqueName.ToUpper())
        {
            case "MAINCATEGORY":
                _Column.Display = false;
                break;
        }
    }
 
    foreach (GridTableView _GridTableView in grdAgingReport.MasterTableView.DetailTables)
        if (_GridTableView.Name == "grdTimePeriods")
        {
            if (_GridTableView.Columns.Count > 0)
                _GridTableView.Columns[0].Visible = false;
            //foreach (GridColumn _Column in _GridTableView.Columns)
            //{
            //    if (_Column.UniqueName.ToUpper() == "SECONDARYCATEGORY")
            //        _Column.Display = false;
            //    break;
            //}
            break;
        }
}

       

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Aug 2012, 06:20 AM
Hi Brian,

Please try the following code to hide a column in the DetailTable.

C#:
protected void grdAgingReport_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "grdTimePeriods")
    {
        GridTableView detailTable = (GridTableView)e.Item.OwnerTableView;
        detailTable.GetColumn("UniqueName").Display = false;
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or