Datagrid and child collections

L

lightsaberwiz

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

DomNewbie

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top