This is a migrated thread and some comments may be shown as answers.

Problems with DataTable as DataSource in grid hierarchy

1 Answer 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan Medley
Top achievements
Rank 1
Jonathan Medley asked on 28 May 2008, 08:37 PM
I've taken the code from the following demo:

http://www.telerik.com/demos/aspnet/Grid/Examples/Programming/Hierarchy/DefaultCS.aspx

and removed the Access data sources and replaced with .Net DataTables returned in a DataSet from a WebService.

The MasterTableView displays the correct rows, however when I attempt to expand a row to view the detail table the area just below the row drops down like it's trying to expand but nothing appears, just white space.

I've also tried creating 2 seperate RadGrids each displaying data from the DataTables and was successful.

Is there anything special I need to do to the DataTables before assigning them as DataSources?

Here's the code-behind (again almost exactly like the demo code except I'm using DataTables as my DataSources):

protected void Page_Load(object sender, EventArgs e)

{

RadGrid RadGrid1 = new RadGrid();

this.PlaceHolder1.Controls.Add(RadGrid1);

if (!IsPostBack)

{

DataSet ds = specTrackService.ReturnDepartures("L1");

DataTable dtShipments = ds.Tables["SRSShipments"];

DataTable dtContainers = ds.Tables["SRSContainers"];

RadGrid1.DataSource = dtShipments;

RadGrid1.MasterTableView.DataKeyNames =

new string[] { "ShipmentNumber" };

RadGrid1.Width =

Unit.Percentage(98);

RadGrid1.PageSize = 5;

RadGrid1.AllowPaging =

true;

RadGrid1.PagerStyle.Mode =

GridPagerMode.NextPrevAndNumeric;

RadGrid1.AutoGenerateColumns =

false;

RadGrid1.Skin =

"Office2007";

RadGrid1.GroupingEnabled =

true;

RadGrid1.ShowGroupPanel =

true;

RadGrid1.ClientSettings.AllowDragToGroup =

false;

RadGrid1.ClientSettings.AllowColumnsReorder =

true;

RadGrid1.MasterTableView.PageSize = 5;

RadGrid1.MasterTableView.Width =

Unit.Percentage(100);

GridBoundColumn boundColumn;

boundColumn =

new GridBoundColumn();

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn.DataField =

"ShipmentNumber";

boundColumn.HeaderText =

"Shipment Number";

boundColumn =

new GridBoundColumn();

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn.DataField =

"Description";

boundColumn.HeaderText =

"Description";

boundColumn =

new GridBoundColumn();

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn.DataField =

"DepartureTime";

boundColumn.HeaderText =

"Departure Time";

boundColumn.ItemStyle.Width =

Unit.Pixel(125);

boundColumn =

new GridBoundColumn();

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn.DataField =

"ScheduledArrivalTime";

boundColumn.HeaderText =

"Scheduled Arrival Time";

boundColumn.ItemStyle.Width =

Unit.Pixel(135);

boundColumn =

new GridBoundColumn();

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn.DataField =

"ActualArrivalTime";

boundColumn.HeaderText =

"Actual Arrival Time";

boundColumn.ItemStyle.Width =

Unit.Pixel(125);

boundColumn =

new GridBoundColumn();

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn.DataField =

"Status";

boundColumn.HeaderText =

"Status";

boundColumn =

new GridBoundColumn();

RadGrid1.MasterTableView.Columns.Add(boundColumn);

boundColumn.DataField =

"SpecimenVolume";

boundColumn.HeaderText =

"Spec Volume";

//details table - Containers for a shipment

GridTableView tvContainers = new GridTableView();

RadGrid1.MasterTableView.DetailTables.Add(tvContainers);

tvContainers.DataSource = dtContainers;

tvContainers.DataKeyNames =

new string[] { "ContainerNumber" };

tvContainers.Width =

Unit.Percentage(100);

GridRelationFields relationFields = new GridRelationFields();

tvContainers.ParentTableRelation.Add(relationFields);

relationFields.MasterKeyField =

"ShipmentNumber";

relationFields.DetailKeyField =

"ShipmentNumber";

boundColumn =

new GridBoundColumn();

tvContainers.Columns.Add(boundColumn);

boundColumn.DataField =

"ContainerNumber";

boundColumn.HeaderText =

"Container Number";

boundColumn =

new GridBoundColumn();

tvContainers.Columns.Add(boundColumn);

boundColumn.DataField =

"Status";

boundColumn.HeaderText =

"Status";
}

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 02 Jun 2008, 08:17 AM
Hello Jonathan Medley,

In order to bind a hierarchical RadGrid programmatically you should use advanced databinding and DetailTableDataBind event to populate the detailtables. Please refer to the online documentation for more details about Hierarchical data-binding using DetailTableDataBind event.

Kind regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Jonathan Medley
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or