This is my code to export my WHDG Records.
protected void lnkExporttoExcell_Click(object sender, EventArgs e)
{
eExporter.DataExportMode = DataExportMode..AllDataInDataSource;
if (eExporter.DataExportMode == DataExportMode..AllDataInDataSource)
WebHierarchicalDataGrid1.DataBind();
}
string fileName = HttpUtility.UrlEncode("Summary");
fileName = fileName.Replace("+", "%20");
eExporter.DownloadName = fileName;
eExporter.WorkbookFormat = Infragistics.Excel.WorkbookFormat.Excel2007;
eExporter.Export(WebHierarchicalDataGrid1);
But the data exported is only the parent which came from a sqldatasource
and it doesnt exported the records from my child band that uses manual on load demand.
I got this Error: System.Exception: DataView has no DataSourceID or DataSource set
private void BindSecondLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)
// Get the data key
int key = (int)e.Row.DataKey[0];
var firstchild = ReadChildFromKey(key); //RETURNS DATABLE
// Create Container Grid
ContainerGrid childGrid = new ContainerGrid();
childGrid.InitializeRow += Child_InitializeeRow;
e.Row.RowIslands.Add(childGrid);
// Bind Child Grid
childGrid.DataKeyFields = "ID";
childGrid.Level = 1;
childGrid.DataSource = firstchild;
childGrid.DataBind();
var view = new Infragistics.Web.UI.DataSourceControls.DataView();
//set the ID of the child view and add it to the WHDS
view.ID = "Child";
WebHierarchicalDataSource1.DataViews.Add(view);
WebHierarchicalDataSource1.DataViews[1].DataSource = first;
// This relation is a join on the ProductID column of the parent and the ID column of the child
var relation = new Infragistics.Web.UI.DataSourceControls.DataRelation("dsourceItemReq_DefaultView", "ItemREQId", "Child", "ItemREQId");
WebHierarchicalDataSource1.DataRelations.Add(relation);
I cannot place data relation on pageload if my childs datatable execute on Child_InitializeeRow.
Hi NewbApps,
From what I can see from your code, you are generating your children based on the DataKey of the row that has fired the event. While using the manual on load would not allow you to export your datatables as they would not be a part of the data source, it may be possible to programmatically bind your child datatables to your parent band using some relation.
For instance, let's imagine that you have a WebHierarchicalDataSource with a DataView from an SqlDataSource. Let the displayed columns be ProductID and ProductName.
You could define the parent-child relationship of your WebHierarchicalDataSource from your code-behind in the Page_Load. The code required would be similar to:
DataTable table = populateDataTable(); //This is your master dataTable containing the child data for all rows Infragistics.Web.UI.DataSourceControls.DataView view = new Infragistics.Web.UI.DataSourceControls.DataView(); //set the ID of the child view and add it to the WHDS view.ID = "Child"; WebHierarchicalDataSource1.DataViews.Add(view); WebHierarchicalDataSource1.DataViews[1].DataSource = table; // This relation is a join on the ProductID column of the parent and the ID column of the child Infragistics.Web.UI.DataSourceControls.DataRelation relation = new Infragistics.Web.UI.DataSourceControls.DataRelation("SqlDataSource1_DefaultView", "ProductID", "Child", "ID"); WebHierarchicalDataSource1.DataRelations.Add(relation); WebHierarchicalDataGrid1.DataSource = WebHierarchicalDataSource1;
DataTable table = populateDataTable(); //This is your master dataTable containing the child data for all rows Infragistics.Web.UI.DataSourceControls.DataView view = new Infragistics.Web.UI.DataSourceControls.DataView();
//set the ID of the child view and add it to the WHDS view.ID = "Child";
WebHierarchicalDataSource1.DataViews.Add(view); WebHierarchicalDataSource1.DataViews[1].DataSource = table;
// This relation is a join on the ProductID column of the parent and the ID column of the child Infragistics.Web.UI.DataSourceControls.DataRelation relation = new Infragistics.Web.UI.DataSourceControls.DataRelation("SqlDataSource1_DefaultView", "ProductID", "Child", "ID"); WebHierarchicalDataSource1.DataRelations.Add(relation); WebHierarchicalDataGrid1.DataSource = WebHierarchicalDataSource1;
Please tell me if this helps.
Petar IvanovDeveloper Support EngineerInfragistics, Inc.http://ko.infragistics.com/support
I am using DataTable in binding my Childbands :
Level | Datasource | Binding | DataKey/Relation
Parent | sqlserver | sqldatasource/view | PK_ItemID
secondLevel | datatable | manual on load demand | PK_ItemDetailID, FK_ItemID
thirdLevel | datatable | manual on load deman | PK_ID,FK_itemDetailID
this is the Example of my code:
protected void btnSearch_Click(object sender, EventArgs e)
WebHierarchicalDataSource1.DataBind();
protected void WebHierarchicalDataGrid1_RowIslandsPopulating(object sender, ContainerRowCancelEventArgs e)
//Cancel the default automatic load on demand operation
e.Cancel = true;
switch (e.Row.Level)
case 0:
BindSecondLevel(e);
break;
case 1:
BindThirdLevel(e);
private void BindThirdLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)
//Logic same as BindSecondLevel child2
protected void Child_InitializeeRow(object sender, RowEventArgs e)
var gridRecord = (ContainerGridRecord)e.Row;
if (gridRecord.Items.Count == 0)
return;
// Sets the ItemREQDetailId Column
var columnItemREQDetailId = (BoundDataField)gridRecord.Items[0].Column;
columnItemREQDetailId.Hidden = true;
protected void Child2_InitializeeRow(object sender, RowEventArgs e)
/ / Same as Child
protected void WebHierarchicalDataGrid1_Init(object sender, EventArgs e)
WebHierarchicalDataGrid1.RowIslandsPopulating += WebHierarchicalDataGrid_RowIslandsPopulating;
WebHierarchicalDataGrid1.InitializeRow += WebHierarchicalDataGrid_InitializeRow;
When you are using manual load on demand with the WHDG, the data for your child bands can not be exported as they are not yet bound to your data source.
Please refer to the DataExportMode API for more information:
http://help.infragistics.com/NetAdvantage/ASPNET/2011.1/CLR4.0/?page=Infragistics4.Web.v11.1~Infragistics.Web.UI.GridControls.DataExportMode.html
Can you provide me with some more information on what type of data source you are using for your child bands ?