HighTechTalks DotNet Forums  

Datagrid and child collections

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss Datagrid and child collections in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
lightsaberwiz@gmail.com
 
Posts: n/a

Default Datagrid and child collections - 12-04-2006 , 12:25 PM






Hi I am writing a program that has the following structure:

YearlySemesterPlans (collection object that contains a collection of
YearlySemesterPlan)
Quote:

---> 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!



Reply With Quote
  #2  
Old   
DomNewbie
 
Posts: n/a

Default Re: Datagrid and child collections - 12-05-2006 , 04:26 AM






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="";
}
}
}


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.