How many levels of nested data could be displayed using WebHierarchicalDataGrid? We need to display 4 levels. Does this control support?
All samples provided are using WebHierarchicalDataSource control for the source. How does WHDG work using WHDS? Does it get data for all childrens during the initial page load and then filters at the client-side using data relations?
Are there any samples that shows how to achieve the same hierarchy using datasets/datatables in code-behind?
I would appreciate your response on this!
Hi,
I created a similar example based on the on demand example shared in this thread up to 6 levels and it working perfectly. But I need to add calculated footer values to every level.
Trying to access the Footer object I got null exception. Please help me to resolve this.
Here is my code.....
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Configuration;using System.Data.SqlClient;using Infragistics.Web.UI.GridControls;using dbTask;
public partial class InfraReports_BalanceSheetRep : System.Web.UI.Page{ private string _connStr = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { if (txtFrom.Text.ToString() == "") { txtFrom.Text = "01/01/" + Convert.ToString(DateTime.Now.Year); } if (txtTo.Text.ToString() == "") { txtTo.Text = "06/30/2017"; } BindGrid(); }
protected void WHDG_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e) { // don't show the arrow for the last level if (((ContainerGridRecord)e.Row).Level < 5) ((ContainerGridRecord)e.Row).IsEmptyParent = true; } protected void WHDG_RowIslandsPopulating(object sender, Infragistics.Web.UI.GridControls.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); break; case 2: case 3: case 4: BindFourthLevel(e.Row.Level, e); break; }
} protected void WHDG_PreRender(object sender, EventArgs e) { if (!IsPostBack) { foreach (ContainerGridRecord row in WHDG.GridView.Rows) { row.IsEmptyParent = true; } } }
private void BindGrid() { DataSet dsData = new DataSet(); BalanceSheetRepository bs = new BalanceSheetRepository(); dsData = bs.GetDataByLevel(1, "0", txtFrom.Text.ToString(), txtTo.Text.ToString()); WHDG.AutoGenerateColumns = true; WHDG.ShowFooter = true;
WHDG.DataSource = dsData; WHDG.DataBind();
// this.WHDG.GridView.Columns[0].Footer.Text = "Sample footer text"; }
private void BindSecondLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e) { // Get the data key String key = e.Row.DataKey[0].ToString(); DataSet dsData = new DataSet(); BalanceSheetRepository bs = new BalanceSheetRepository(); dsData = bs.GetDataByLevel(2, key, txtFrom.Text.ToString(), txtTo.Text.ToString());
// Create Container Grid ContainerGrid childGrid = new ContainerGrid(); e.Row.RowIslands.Add(childGrid);
// Bind Grid childGrid.DataKeyFields = "AccountTypeId"; childGrid.ShowFooter = true; childGrid.Level = 1; childGrid.DataSource = dsData; childGrid.DataBind(); }
private void BindThirdLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e) { // Get the data key String key = e.Row.DataKey[0].ToString();
DataSet dsData = new DataSet(); BalanceSheetRepository bs = new BalanceSheetRepository(); dsData = bs.GetDataByLevel(3, key, txtFrom.Text.ToString(), txtTo.Text.ToString());
// Bind Grid childGrid.DataKeyFields = "ScheduleId"; childGrid.Level = 2; childGrid.DataSource = dsData; childGrid.DataBind(); }
private void BindFourthLevel(int level, Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e) { // Get the data key String key = e.Row.DataKey[0].ToString();
DataSet dsData = new DataSet(); BalanceSheetRepository bs = new BalanceSheetRepository(); dsData = bs.GetDataByLevel((level + 2), key, txtFrom.Text.ToString(), txtTo.Text.ToString());
// Bind Grid if (level == 2) { childGrid.DataKeyFields = "AccountId"; childGrid.Level = 3; } else if (level == 3){ childGrid.DataKeyFields = "LedgerId"; childGrid.Level = 4; } else if (level == 4) { childGrid.DataKeyFields = "LedgerId"; childGrid.Level = 5; } childGrid.DataSource = dsData; childGrid.DataBind();
}
protected void WHDG_DataBound(object sender, EventArgs e)
{ double total = 0; foreach (ContainerGridRecord row in this.WHDG.GridView.Rows) { total += Convert.ToDouble(row.Items[2].Text.Trim()); } // this.WHDG.GridView.Columns[0].Footer.Text = total.ToString(); // this.WHDG.GridView.Band.Bands[0].Bands[0].Columns["Balance"].Footer.Text = total.ToString();
protected void WHDG_RowIslandsPopulated(object sender, ContainerRowEventArgs e) { e.Row.RowIslands[0].Columns[0].Footer.Text = "Sample footer text"; e.Row.RowIslands[0].ShowFooter = true; }}