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

How do I create a Hierarchy nested view programmatically

12 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dean
Top achievements
Rank 1
Dean asked on 20 Aug 2011, 01:08 PM
Hi,

 I am trying to create this http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx

100% programmatically.

Can anyone help please?

Thank you!

Dean

12 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Aug 2011, 09:56 PM
Hello,

<telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
       <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
       </telerik:RadAjaxManager>
       <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
namespace TelerikTest.Web
{
    public partial class GridWithNestedViewTempleteDemo : System.Web.UI.Page
    {
        protected void Page_Init(object sender, System.EventArgs e)
        {
            DefineGridStructure();
        }
 
        protected void Page_Load(object sender, System.EventArgs e)
        {
            RadGrid grid = (RadGrid)PlaceHolder1.FindControl("RadGrid1");
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(grid, grid);
        }
        private void DefineGridStructure()
        {
            RadGrid RadGrid1 = new RadGrid();
            RadGrid1.ID = "RadGrid1";
 
             
 
            RadGrid1.Width = Unit.Percentage(100);
            RadGrid1.PageSize = 5;
            RadGrid1.AllowPaging = true;
            RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
            RadGrid1.AutoGenerateColumns = false;
            RadGrid1.GroupingEnabled = true;
            RadGrid1.ShowGroupPanel = true;
            RadGrid1.ClientSettings.AllowDragToGroup = true;
 
            RadGrid1.MasterTableView.DataKeyNames = new string[] { "ID" };
 
            GridBoundColumn boundColumn;
 
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "ID";
            boundColumn.HeaderText = "ID";
            boundColumn.UniqueName = "ID";
            RadGrid1.MasterTableView.Columns.Add(boundColumn);
 
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Name";
            boundColumn.HeaderText = "Name";
            boundColumn.UniqueName = "Name";
            RadGrid1.MasterTableView.Columns.Add(boundColumn);
 
            RadGrid1.MasterTableView.NestedViewTemplate =new MyTemplate();
 
            //RadGrid1.DataSourceID = "SqlDataSource1";
            //or
            RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
            this.PlaceHolder1.Controls.Add(RadGrid1);
        }
        protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
 
            RadGrid RadGrid1 = sender as RadGrid;
 
            dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"},
                new { ID = 4, Name = "Name4"},
                new { ID = 5, Name = "Name5"},
                new { ID = 6, Name ="Name6"},
                new { ID = 7, Name = "Name7"},
                new { ID = 8, Name = "Name8"},
                new { ID = 9, Name = "Name9"},
                new { ID = 10, Name = "Name10"},
                new { ID = 11, Name ="Name11"},
                new { ID = 12, Name = "Name12"},
                new { ID = 13, Name = "Name13"},
                new { ID = 14, Name = "Name14"},
                new { ID = 15, Name = "Name15"}
            };
 
            RadGrid1.DataSource = data;
        }
 
    }
 
    public class MyTemplate : ITemplate
    {
 
        protected TextBox textBox;// to add a TextBox control in the NestedViewTemplate
 
        public void InstantiateIn(System.Web.UI.Control container)
        {
            textBox = new TextBox();
            textBox.ID = "NestedTextBox";
            container.Controls.Add(textBox);
 
        }
 
    }
}


Thanks,
Jayesh Goyani
0
Dean
Top achievements
Rank 1
answered on 22 Aug 2011, 11:27 AM
Hi,

Thank you, this code worked fine, however, partial solution, I was after the complete solution. i.e. RadTAbStrip, Multipage, loading data from the database etc etc,  I want everything u see in that demo written programmatically.

Sorry for asking so much!

Thanks

Dean
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Aug 2011, 04:48 PM
Hello,

Currently i am working on it and i found one issue in it so after solving/completing  this i will inform you here.

Note : sorry in advance because due to busy schedule i am not able to giving enough time to this project so.

Thanks,
Jayesh Goyani
0
Dean
Top achievements
Rank 1
answered on 23 Aug 2011, 07:16 PM
Thank you ever so much!
0
Dean
Top achievements
Rank 1
answered on 23 Aug 2011, 07:26 PM
I may required your services if this is exactly what I want! thanks again!!!
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 02:39 PM
Hello,

Sorry for late.

Programmatic creation of RadGrid / Hierarchy with Templates

let me know if any concern.


Thanks,
Jayesh Goyani
0
Dean
Top achievements
Rank 1
answered on 26 Aug 2011, 03:39 PM
Thank you so much! very helpful!

I have a request, in the real world child rows in the hierarchy should only be executed after the user has expanded the row, how could you get your example working so the child rows only get executed after the row has been expanded?

At the moment you have the overhead of running code in the next hierarchical level even though the user hasn't expanded the row...

Thank you

Dean
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 04:22 PM
Hello,

please send screen shot of what you want.

i m not understand you.

Thanks,
Jayesh Goyani
0
Dean
Top achievements
Rank 1
answered on 26 Aug 2011, 05:14 PM
I want 2nd layer (tabs) to only load on demand. I want child view to only load when user expand's the grid row.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Aug 2011, 07:29 PM
Hello,

innergrid.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerBind;

let me know if any concern.

Thanks,
Jayesh Goyani
0
Dean
Top achievements
Rank 1
answered on 27 Aug 2011, 07:37 AM
Thank you. How do I use your code to make contact information ie date of birth load when the user expands the parent row?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Aug 2011, 09:02 AM
Hello,

RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerBind;

if this is not your case then elaborate your scenario.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Dean
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Dean
Top achievements
Rank 1
Share this question
or