protected override void OnInit(EventArgs e)
{
base.OnInit(e);
/* Provide flat datasource only for the parent band. * /
this.whdg1.DataSource = GetPeople();
}
bool isChild = false;
protected void whdg1_InitializeRow(object sender, RowEventArgs e)
{
/* If the event is not raised for a row from the child grid
set IsEmptyParent = true
the property will show up the expand indicator for the parent Band. */
if (isChild == false)
((ContainerGridRecord)e.Row).IsEmptyParent = true;
}
/* This event is called when the user expand a row from the parent band.
First of all the event is canceled and new ContainerGrid is created
and bound to data. This is where the child band is created
and sent down to the client. */
protected void whdg1_RowIslandsPopulating(object sender, Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)
{
e.Cancel = true;
ContainerGrid child = new ContainerGrid();
child.InitializeRow += new InitializeRowEventHandler(child_InitializeRow);
e.Row.RowIslands.Add(child);
child.DataSource = GetAddresses();
child.DataBind();
}
/* This event is called for each child row being initialized * /
void child_InitializeRow(object sender, RowEventArgs e)
{
isChild = true;
}
#region Entities
public class Person
{
public int _addressID;
public int ID { get; set; }
public string Fname { get; set; }
public string Sname { get; set; }
public int Addresses
{
get { return _addressID; }
}
}
public class Address
{
public int ID { get; set; }
public string Street { get; set; }
public string City { get; set; }
}
#endregion
#region Data
private List<Person> GetPeople()
{
List<Person> list = new List<Person>();
list.Add(
new Person() { ID = 1, Fname = "Oliver", Sname = "George", _addressID = 1 });
list.Add(
new Person() { ID = 2, Fname = "Jack", Sname = "Joseph", _addressID = 1 });
list.Add(
new Person() { ID = 3, Fname = "Harry", Sname = "Jacob", _addressID = 1 });
list.Add(
new Person() { ID = 4, Fname = "Thomas", Sname = "Simeonov", _addressID = 2 });
list.Add(
new Person() { ID = 5, Fname = "Charlie", Sname = "Dylan", _addressID = 2 });
list.Add(
new Person() { ID = 6, Fname = "William", Sname = "Lewis", _addressID = 2 });
list.Add(
new Person() { ID = 7, Fname = "James", Sname = "Max", _addressID = 2 });
list.Add(
new Person() { ID = 8, Fname = "Daniel", Sname = "Jayden", _addressID = 2 });
return list;
}
private List<Address> GetAddresses()
{
List<Address> list = new List<Address>();
list.Add(
new Address() { ID = 1, City = "Windsor", Street = "Corporate Park 50 Millstone Road" });
list.Add(
new Address() { ID = 2, City = "Sofia", Street = "110 B, Simeonovsko Shosse Office Floor II" });
return list;
}