Hi I am writing a program that has the following structure: YearlySemesterPlans (collection object that contains a collection of YearlySemesterPlan) | | |---> YearlySemesterPlan (Object that holds a semester 'year' and uses that to grab a child object 'SemesterPlans') | | | |---->SemesterPlans(collection object that contains SemesterPlan) | | | |----->SemesterPlan(Grabs the plan for a students semester (just basic information)) so basically if i call: YearlySemesterPlans _plans; _plans = Namespace.YearlySemesterPlans.GetObj(12345); I would get a collection object that sorts all the information by year (and semester) OKAY now that I got some background on the problem, I have a master datagrid, and I want to add datagrids to the master one that contains the child objects 'SemesterPlans' How would i do that? Thanks!
Something like this works...Add the grid to a cell in the ItemDataBound of the master grid. private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { //When each row is created in the DataGrid, eval the ItemType if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //If the ItemType is Item or AlternatingItem, //Create a new DataGrid object named UserDetailGrid DataGrid UserDetailGrid = new DataGrid(); //Format the DataGrid to look cool. UserDetailGrid.BorderWidth = (Unit)1; UserDetailGrid.CellPadding = 2; UserDetailGrid.CellSpacing = 0; UserDetailGrid.GridLines = GridLines.Both; UserDetailGrid.BorderColor = Color.FromName("Black"); UserDetailGrid.ItemStyle.Font.Size = FontUnit.XXSmall; UserDetailGrid.AlternatingItemStyle.BackColor = Color.FromName("Tan"); UserDetailGrid.ShowHeader = true; UserDetailGrid.HeaderStyle.BackColor = Color.FromName("Black"); UserDetailGrid.HeaderStyle.ForeColor = Color.FromName("White"); UserDetailGrid.HeaderStyle.Font.Bold = false; UserDetailGrid.HeaderStyle.Font.Size =FontUnit.XXSmall; //Do not autogenerate columns. UserDetailGrid.AutoGenerateColumns = false; BoundColumn bc = new BoundColumn(); //Set the BoundColumn Values bc.HeaderText = "Full Name"; bc.DataField = "Full Name"; bc.ItemStyle.Wrap = true; bc.ItemStyle.Width =240; UserDetailGrid.Columns.Add(bc); bc = new BoundColumn(); bc.HeaderText = "Company"; bc.DataField = "Company"; bc.ItemStyle.Wrap = true; bc.ItemStyle.Width =120; UserDetailGrid.Columns.Add(bc); bc = new BoundColumn(); bc.HeaderText = "Date"; bc.DataField = "Date"; bc.ItemStyle.Wrap = true; bc.ItemStyle.Width =180; UserDetailGrid.Columns.Add(bc); bc = new BoundColumn(); bc.HeaderText = "Time"; bc.DataField = "Time"; bc.ItemStyle.Wrap = true; bc.ItemStyle.Width =80; UserDetailGrid.Columns.Add(bc); bc = new BoundColumn(); bc.HeaderText = "Site Vists"; bc.DataField = "Site Vists"; bc.ItemStyle.Wrap = true; bc.ItemStyle.Width =80; UserDetailGrid.Columns.Add(bc); bc = new BoundColumn(); bc.HeaderText = "IP Address"; bc.DataField = "IP Address"; bc.ItemStyle.Wrap = false; bc.ItemStyle.Width =80; UserDetailGrid.Columns.Add(bc); //****End BoundColumns****// DataView userView = db.BrowsingDetails.Tables["UserDetails"].DefaultView; userView.RowFilter = "YachtID='" + e.Item.Cells[2].Text + "'"; if (userView.Count!=0) { //Bind the DataGrid. UserDetailGrid.DataSource = userView; UserDetailGrid.DataBind(); //Hide the YachtID // UserDetailGrid.Columns[3].Visible=false; //Add the UserDetailGrid to the BooksDataGrid. e.Item.Cells[2].Controls.Add(UserDetailGrid); } else { e.Item.Cells[2].Text=""; } } }
Don't see what you're looking for? Try a search.
|