After looping the parent rows/columns of the grid, I want to calculate special totals of the columns and write these as strings to the footer (columns). Using e.rowisland.rows()...items() I am able to calculate the required values...but I cannot figure out how to write a client-side string to the footer (columns) row. Any help will be appreciated.
Jim Spicer
Hi Jim,
You should be able to write to a footer by setting the Text property of the Footer property of a column. So for example, to set the text of column 0's footer in the top grid view, you could use
this.WebHierarchicalDataGrid1.GridView.Columns[0].Footer.Text = "Hello";
I put the following code in the hierarchical grid's DataBound event to set the sum of column 0, an integer column.
protected void WebHierarchicalDataGrid1_DataBound(object sender, EventArgs e) { int total = 0; foreach (ContainerGridRecord row in this.WebHierarchicalDataGrid1.GridView.Rows) { total += int.Parse(row.Items[0].Text); } this.WebHierarchicalDataGrid1.GridView.Columns[0].Footer.Text = total.ToString(); }
Let us know if you need more help with this.
regards,David Young
HI David
I am getting same kind of issue when I am setting sum @footer text at band, it is not showing, can you suggest where is wrong
protected void grdEstBidder_DataBound(object sender, EventArgs e) { decimal total = 0; decimal unitPrice = 0; foreach (ContainerGridRecord row in this.grdEstBidder.GridView.Rows) { if (row != null) { for (int j = 0; j < row.RowIslands.Count; j++) { ContainerGridRecord row2 = (ContainerGridRecord)row.RowIslands[0].Rows[j]; if (row2 != null) { for (int iItemCnt = 0; iItemCnt < row2.Items.Count; iItemCnt++) { ContainerGridRecord row3 = (ContainerGridRecord)row2.RowIslands[0].Rows[iItemCnt]; if (row3 != null) { total += Convert.ToDecimal(row3.Items[row3.Items.FindItemByKey("Total").Index].Value); unitPrice += Convert.ToDecimal(row3.Items[row3.Items.FindItemByKey("UnitPrice").Index].Value); } } } } } } this.grdEstBidder.GridView.Band.Bands[0].Bands[0].Columns["Total"].Footer.Text = total.ToString(); this.grdEstBidder.GridView.Band.Bands[0].Bands[0].Columns["UnitPrice"].Footer.Text = unitPrice.ToString(); }