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

problem with invisible columns in grid hierarchy

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tibor
Top achievements
Rank 1
Tibor asked on 17 Nov 2010, 06:27 PM
Hello I have some problem with nestedview template and I hope that I find the answer here.

In the attached code I have a sample with my problem.
I have a hierarchical grid made up with NestedViewTemplate (no detail tables)
In the detail table i have two columns set to visible="false". But they are binded manualy(via eval) in a nested view template. Also I have defined a norecord template.
My problem is, that when I push the insert button, the grid style goes wrong. There is still visible a part of norecord template, and the edit form is in the right side of the grid.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <telerik:RadGrid
            DataSourceID="ObjectDataSource1"
            Skin="Vista"
            GridLines="None"
            AutoGenerateColumns="False"
            ID="RadGrid1"
            runat="server">
            <MasterTableView
                CommandItemDisplay="Top"
                DataKeyNames="ID"
                EnableNoRecordsTemplate="true"
                DataSourceID="ObjectDataSource1" >
                <NestedViewTemplate>
                    <asp:Panel runat="server" ID="InnerContainer" Visible="false">
                        <telerik:RadTabStrip ID="RadTabStrip1" MultiPageID="mpLocalizationDataSection"
                            runat="server" SelectedIndex="2" Skin="Vista">
                            <Tabs>
                                <telerik:RadTab
                                    runat="server"
                                    Text="Tabulka 1"                                    
                                    PageViewID="pgv" >
                                </telerik:RadTab>  
                                <telerik:RadTab
                                    runat="server"
                                    Text="Tabulka 2"                                    
                                    PageViewID="pgv2" >
                                </telerik:RadTab>                             
                            </Tabs>
                        </telerik:RadTabStrip>
                        <telerik:RadMultiPage
                            runat="server"
                            ID="mpLocalizationDataSection"
                            SelectedIndex="2"
                            RenderSelectedPageOnly="false" >
                            <telerik:RadPageView runat="server" ID="pgv">
                                <telerik:RadGrid
                                    ID="RadGrid2"
                                    Width="100%"
                                    DataSourceID="ObjectDataSource2"
                                    Skin="Vista"
                                    GridLines="None"                                   
                                    AutoGenerateColumns="false"
                                    runat="server" onprerender="RadGrid2_PreRender">
                                    <MasterTableView
                                        CommandItemDisplay="Top"
                                        AutoGenerateColumns="false"                                       
                                        DataKeyNames="ID"
                                        Width="100%"
                                        ExpandCollapseColumn-Display="false"
                                        ExpandCollapseColumn-Visible="false"
                                        EnableNoRecordsTemplate="true"
                                        DataSourceID="ObjectDataSource2" >                                       
                                         
                                        <Columns>
                                            <telerik:GridBoundColumn
                                                HeaderText="ID"
                                                Visible="false"
                                                DataField="ID" >                       
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn
                                                HeaderText="Meno"
                                                Visible="false"
                                                DataField="Name" >                       
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                        <NestedViewTemplate>
                                            <asp:Panel ID="NesteViewPanel" runat="server">
                                                <asp:Label
                                                    runat="server"
                                                    ID="lblLocationPremisesTypeCode"
                                                    Text='<%# (Eval("ID")) %>' >
                                                </asp:Label>
                                                <asp:Label
                                                    runat="server"
                                                    ID="Label3"
                                                    Text='<%# (Eval("Name")) %>' >
                                                </asp:Label>
                                            </asp:Panel>
                                        </NestedViewTemplate>
                                         
                                    </MasterTableView>
                                </telerik:RadGrid>
                                <asp:ObjectDataSource
                                    ID="ObjectDataSource2"
                                    DataObjectTypeName="TestRadgridInsert.DTO2"
                                    TypeName="TestRadgridInsert.DS1"
                                    SelectMethod="Select2"
                                    runat="server">
                                </asp:ObjectDataSource>
                            </telerik:RadPageView>
                            <telerik:RadPageView runat="server" ID="pgv2">
                                text
                            </telerik:RadPageView>
                        </telerik:RadMultiPage>
                    </asp:Panel>
                </NestedViewTemplate>
 
                <Columns>
                    <telerik:GridBoundColumn
                        HeaderText="ID"
                        DataField="ID" >                       
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn
                        HeaderText="Meno"
                        DataField="Name" >                       
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        <asp:ObjectDataSource
            ID="ObjectDataSource1"
            DataObjectTypeName="TestRadgridInsert.DTO1"
            TypeName="TestRadgridInsert.DS1"
            SelectMethod="Select1"           
            runat="server">
        </asp:ObjectDataSource>       
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
namespace TestRadgridInsert
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadGrid1.ItemCreated += new Telerik.Web.UI.GridItemEventHandler(RadGrid1_ItemCreated);
            RadGrid1.PreRender += new EventHandler(RadGrid1_PreRender);
            RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
        }
        void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                ((GridDataItem)e.Item).ChildItem.FindControl("InnerContainer").Visible = !e.Item.Expanded;
            }
        }
        void RadGrid1_PreRender(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RadGrid1.MasterTableView.Items[0].Expanded = true;
                RadGrid1.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
            }
        }
        void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridNestedViewItem)
            {
                e.Item.FindControl("InnerContainer").Visible = ((GridNestedViewItem)e.Item).ParentItem.Expanded;
            }
        }
        protected void RadGrid2_PreRender(object sender, EventArgs e)
        {
            RadGrid grid = sender as RadGrid;
            if (grid.MasterTableView.Items.Count > 0)
            {
                grid.MasterTableView.Items[0].Expanded = true;
                GridExpandColumn collapseCol = grid.MasterTableView.ExpandCollapseColumn as GridExpandColumn;
                //collapseCol.Display = false;
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace TestRadgridInsert
{
    public class DS1
    {
        public List<DTO1> Select1()
        {
            List<DTO1> list = new List<DTO1>();
            for (int i = 0; i < 3; i++)
            {
                DTO1 dto1 = new DTO1();
                dto1.ID = i;
                dto1.Name = "meno " + i.ToString();
                list.Add(dto1);
            }
            return list;
        }
        public List<DTO2> Select2()
        {
            List<DTO2> list = new List<DTO2>();
            //for (int i = 0; i < 1; i++)
            //{
            //    DTO2 dto2 = new DTO2();
            //    dto2.ID = i;
            //    dto2.Name = "meno " + i.ToString();
            //    list.Add(dto2);
            //}
            return list;
        }
        public void Insert2(DTO2 item)
        {
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace TestRadgridInsert
{
    public class DTO1
    {
        public DTO1()
        {
        }
 
        public int ID { get; set; }
        public string Name { get; set; }
    }
 
    public class DTO2
    {
        public DTO2()
        {
        }
 
        public int ID { get; set; }
        public string Name { get; set; }
    }
}


Thank you very much for answers and some solution.

With regards

Tibor

2 Answers, 1 is accepted

Sort by
0
Tibor
Top achievements
Rank 1
answered on 18 Nov 2010, 09:11 AM
I forgot to send an image how the grid looks like. Here it is.
0
Marin
Telerik team
answered on 23 Nov 2010, 04:06 PM
Hi Tibor,

You should have at least one column visible in the nested grid. Otherwise you will not be able to expand the nested view template (the one with the two labels inside) because you will not see any items in the grid. The misalignment that you see is due to the lack of visible column in the inner grid, which leads to the effect that the only column left, which is the expand collapse column, stretches to occupy the whole available place. To fix the problem you need to remove the settings for visible=false and display=false for the expand collapse column and to set visible=true for the second column. This way the insert form will be aligned properly. Here is the code snippet for the changes:
<MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false" DataKeyNames="ID"
                                       Width="100%" ExpandCollapseColumn-Display="false" ExpandCollapseColumn-Visible="false"
                                          
                                       EnableNoRecordsTemplate="true" DataSourceID="ObjectDataSource2">
                                       <Columns>
                                           <telerik:GridBoundColumn HeaderText="ID" Visible="true" DataField="ID">
                                           </telerik:GridBoundColumn>
                                           <telerik:GridBoundColumn HeaderText="Meno" Visible="true" DataField="Name">
                                           </telerik:GridBoundColumn>
                                       </Columns>

All the best,
Marin
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Tibor
Top achievements
Rank 1
Answers by
Tibor
Top achievements
Rank 1
Marin
Telerik team
Share this question
or