Hide detail table columns in RadGrid.PreRender is not working

3 posts, 1 answers
  1. neebs
    neebs avatar
    106 posts
    Member since:
    Apr 2007

    Posted 04 Sep 2010 Link to this post

    I'm trying to suppress the display of columns in the master table and in detail grids in the PreRender event. This is as suggested in other Telerik responses to postings. The master table behaves as expected, but the detail tables do not suppress their columns. The code is below:

    protected void RadGridLot_PreRender(object sender, EventArgs e)
    {
        switch (RadComboBoxFilter.SelectedItem.Value)
        {
            case WECOBLL.WECODefs.sLotOpen:
                RadGridLot.MasterTableView.GetColumn("AddJob").Visible = true;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Action1").Visible = true;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Action2").Visible = true;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Form1").Visible = true;
                RadGridLot.MasterTableView.GetColumn("OutgoingNetWeightTotal").Visible = false;
                break;
            case WECOBLL.WECODefs.sLotShipped:
                RadGridLot.MasterTableView.GetColumn("AddJob").Visible = false;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Action1").Visible = true;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Action2").Visible = false;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Form1").Visible = true;
                RadGridLot.MasterTableView.GetColumn("OutgoingNetWeightTotal").Visible = true;
                break;
            case WECOBLL.WECODefs.sLotClosed:
                RadGridLot.MasterTableView.GetColumn("AddJob").Visible = false;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Action1").Visible = false;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Action2").Visible = false;
                RadGridLot.MasterTableView.DetailTables[0].GetColumn("Form1").Visible = true;
                RadGridLot.MasterTableView.GetColumn("OutgoingNetWeightTotal").Visible = true;
                break;
        }
    }

    and the markup:

    <telerik:RadGrid ID="RadGridLot" runat="server"
                DataSourceID="ObjectDataSourceLots" GridLines="None"
                ondetailtabledatabind="RadGridLot_DetailTableDataBind"
                AllowAutomaticInserts="True" AutoGenerateColumns="False"
                oninsertcommand="RadGridLot_InsertCommand" Skin="Web20"
                onitemcommand="RadGridLot_ItemCommand" onprerender="RadGridLot_PreRender"
                AllowSorting="True" onneeddatasource="RadGridLot_NeedDataSource"
                onitemcreated="RadGridLot_ItemCreated">
                <ClientSettings>
                    <Scrolling AllowScroll="True" ScrollHeight="600px" />
                </ClientSettings>
                <MasterTableView
                    DataSourceID="ObjectDataSourceLots" DataKeyNames="Name,Id"
                    CommandItemDisplay="Top" AllowNaturalSort="False"
                    HierarchyDefaultExpanded="True">
                <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
                </RowIndicatorColumn>
                    <DetailTables>
                        <telerik:GridTableView Name="Jobs" runat="server"
                            DataSourceID="ObjectDataSourceJobs" DataKeyNames="Id"
                            NoDetailRecordsText="No Jobs to display." BackColor="#FFFFCC"  >
                            <RowIndicatorColumn>
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <DetailTables>
                                <telerik:GridTableView runat="server" Name="Bins" DataKeyNames="Id"
                                    NoDetailRecordsText="No Bins to display.">
                                <CommandItemSettings></CommandItemSettings>
                                <Columns>
                                    <telerik:GridTemplateColumn DataField="Id" DataType="System.Int64"
                                        HeaderText="Job Id" SortExpression="Id" UniqueName="Id"
                                        Visible="False">
                                        <ItemTemplate>
                                            <asp:Label ID="JobIdLabel" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="Name" HeaderText="Bin"
                                        SortExpression="Name" UniqueName="Name">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridNumericColumn DataField="AverageMoistureAsFraction" DataType="System.Double"  DataFormatString="{0:P1}"
                                        HeaderText="Avg. Moisture" SortExpression="AverageMoistureAsFraction" UniqueName="JobAverageMoistureAsFraction">
                                        <HeaderStyle HorizontalAlign="Center" />
                                        <ItemStyle HorizontalAlign="Center" />
                                    </telerik:GridNumericColumn>
                                    <telerik:GridCheckBoxColumn DataField="DoorIsOpen" DataType="System.Boolean" HeaderText="Door Open" UniqueName="DoorisOpen" >
                                        <HeaderStyle HorizontalAlign="Center" />
                                        <ItemStyle HorizontalAlign="Center" />
                                    </telerik:GridCheckBoxColumn>
                                    <telerik:GridCheckBoxColumn DataField="IsManual" DataType="System.Boolean" HeaderText="Manual" UniqueName="IsManual" >
                                        <HeaderStyle HorizontalAlign="Center" />
                                        <ItemStyle HorizontalAlign="Center" />
                                    </telerik:GridCheckBoxColumn>
                                </Columns>
                                </telerik:GridTableView>
                            </DetailTables>
     
    <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
     
                            <ExpandCollapseColumn Visible="True">
                            </ExpandCollapseColumn>
                            <Columns>
                                <telerik:GridTemplateColumn DataField="Id" DataType="System.Int64"
                                    HeaderText="Job Id" SortExpression="Id" UniqueName="Id"
                                    Visible="False">
                                    <ItemTemplate>
                                        <asp:Label ID="JobIdLabel" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn DataField="JobRefFormatted" HeaderText="Job Reference"
                                    SortExpression="JobRefFormatted" UniqueName="JobRefFormatted">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="JobStage" HeaderText="Stage"
                                    SortExpression="JobStage" UniqueName="JobStage">
                                </telerik:GridBoundColumn>
                                <telerik:GridDateTimeColumn DataField="StartTime" DataType="System.DateTime"  DataFormatString="{0:MM/dd hh:mm tt}"
                                    HeaderText="StartTime" SortExpression="StartTime" UniqueName="StartTime">
                                </telerik:GridDateTimeColumn>
                                <telerik:GridNumericColumn DataField="JobAverageMoistureAsFraction" DataType="System.Double"  DataFormatString="{0:P1}"
                                    HeaderText="Avg. Moisture" SortExpression="JobAverageMoistureAsFraction" UniqueName="JobAverageMoistureAsFraction">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Center" />
                                </telerik:GridNumericColumn>
                                <telerik:GridBoundColumn DataField="OutgoingReceiptNumber" HeaderText="Ship Receipt #"
                                    SortExpression="OutgoingReceiptNumber" UniqueName="OutgoingReceiptNumber">
                                </telerik:GridBoundColumn>
                                <telerik:GridButtonColumn CommandName="Action1" UniqueName="Action1" Text="" ></telerik:GridButtonColumn>
                                <telerik:GridButtonColumn CommandName="Action2" UniqueName="Action2" Text="" ></telerik:GridButtonColumn>
                                <telerik:GridButtonColumn CommandName="Form1" UniqueName="Form1" Text="" ></telerik:GridButtonColumn>
                          </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                    <CommandItemSettings AddNewRecordText="Enter New Lot"
                        ShowRefreshButton="False" />
                    <ExpandCollapseColumn >
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridTemplateColumn DataField="LocationId" DataType="System.Int64"
                            HeaderText="LocationId" SortExpression="LocationId" UniqueName="LocationId"
                            Visible="False">
                            <ItemTemplate>
                                <asp:Label ID="LocationIdLabel" runat="server" Text='<%# Eval("LocationId") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="LotRefFormatted" HeaderText="Lot Reference"
                            SortExpression="LotRefFormatted" UniqueName="LotRefFormatted">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Grower" HeaderText="Grower"
                            SortExpression="Grower" UniqueName="Grower">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Variety" HeaderText="Variety"
                            SortExpression="Variety" UniqueName="Variety">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Field" HeaderText="Block"
                            SortExpression="Field" UniqueName="Field">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="EstimatedNumberOfBins"
                            DataType="System.Int64" HeaderText="Est. # Of Bins"
                            SortExpression="EstimatedNumberOfBins" UniqueName="EstimatedNumberOfBins">
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemStyle HorizontalAlign="Center" />
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn DataField="Id" DataType="System.Int64"
                            HeaderText="Id" SortExpression="Id" UniqueName="Id" Visible="False">
                            <ItemTemplate>
                                <asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="Name" HeaderText="Name"
                            SortExpression="Name" UniqueName="Name" Visible="False">
                            <ItemTemplate>
                                <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridNumericColumn DataField="OutgoingNetWeightTotal" DataType="System.Double" 
                            HeaderText="Outgoing Net Wt." SortExpression="OutgoingNetWeightTotal" UniqueName="OutgoingNetWeightTotal">
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemStyle HorizontalAlign="Center" />
                        </telerik:GridNumericColumn>
                        <telerik:GridBoundColumn DataField="ReceivedOn" DataType="System.DateTime"   DataFormatString="{0:MM/dd hh:mm tt}"
                            HeaderText="Received On" SortExpression="ReceivedOn" UniqueName="ReceivedOn">
                        </telerik:GridBoundColumn>
                        <telerik:GridButtonColumn CommandName="EditLot" UniqueName="EditLot" Text="Edit Lot" ></telerik:GridButtonColumn>
                        <telerik:GridButtonColumn CommandName="AddJob" UniqueName="AddJob" Text="Create Job" ></telerik:GridButtonColumn>
                    </Columns>
                    <CommandItemTemplate>
                        <asp:Button ID="ButtonInsert" runat="server" Text="+"  OnClientClick="return ShowInsertLotForm();" />
                        <a href="#" onclick="return ShowInsertLotForm();">Add New Lot</a>
                    </CommandItemTemplate>
                </MasterTableView>
            </telerik:RadGrid>

    Thanks, Steve
  2. Answer
    Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 07 Sep 2010 Link to this post

    Hi Steve,

    You could try hiding the columns using the approach suggested by my colleague at that address. Please, note what he explains in the post:

    The GridTableView.DetailTables collection is only a set of templates for creating the nested tables. The real detail tables are contained in the GridDataItem.ChildItem.NestedTableViews collection.

    Greetings,
    Tsvetina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. neebs
    neebs avatar
    106 posts
    Member since:
    Apr 2007

    Posted 17 Sep 2010 Link to this post

    Thanks, I've adapted this approach to my needs and it works.

    Steve
Back to Top