Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Data » Downloads
 
Add your own
alternative version

Multilevel Nested Master/Detail Data Display Using GridView

, 18 Jul 2006
How GridViews can be used to show data having multilevel master detail relationships.
multinestmdgridview_src.zip
MultilevelNestedMasterDetailUsingGridView_src
App_Data
Global.asax
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ParentGridView_OnRowEditing(object sender, GridViewEditEventArgs e)
    {
        int parent_index = e.NewEditIndex;
        
        //to set the edit index of the Parent grid with that of the current row
        ParentGridView.EditIndex = parent_index;
        ParentGridView.DataBind();
        //find the pubid_lbl containing pub_id in that particular row by using findcontrol method
        GridViewRow row = ParentGridView.Rows[parent_index];
        Label pub_id_lbl = (Label)row.FindControl("pubid_lbl");
       
        //save pub_id and edit_index in session for childgridview's use
        Session["PubID"] = Convert.ToInt32(pub_id_lbl.Text);
        Session["ParentGridViewIndex"] = parent_index;

   }
    protected void ChildGridView_OnRowEditing(object sender, GridViewEditEventArgs e)
    {

        //set the edit index of the child gridview with that of the current row
        int parent_index =(int)Session["ParentGridViewIndex"];
        GridViewRow parent_row = ParentGridView.Rows[parent_index];
        GridView ChildGridiView = (GridView)parent_row.FindControl("ChildGridView");

        int child_index = e.NewEditIndex;
        ChildGridiView.EditIndex = child_index;
        ChildGridiView.DataBind();
        //find the titleid_lbl in that particular row by using findcontrol method
        GridViewRow child_row = ChildGridiView.Rows[child_index];
        Label titleid_lbl = (Label)child_row.FindControl("titleid_lbl");
        // save the title_id in session for grandchildgridview's use
        Session["TitleID"] = titleid_lbl.Text;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Mahr G Mohyuddin
Software Developer (Senior)
Pakistan Pakistan
Mohyuddin is a Senior Software Engineer with BS Honors degree in Computer Science from Punjab University College of Information Technology (PUCIT),Lahore Pakistan. His interest and expertise are in Microsoft technologies specially SharePoint 2010, InfoPath 2010 , Workflow , MS Dynamics CRM, ASP.NET 2.0/3.0, ASP.NET MVC, C#,ADO.NET, LINQ , SQl Server ,Ajax, JQuery. Currently he is working at VeriPark Gulf, Dubai, UAE. He can be reached at gmohyd at g mail.com.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 18 Jul 2006
Article Copyright 2006 by Mahr G Mohyuddin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid