Multiple Footer Rows

A

Alan Z. Scharf

1. I have a datagrid with two footer template rows inserted in HTML design
tab. Each footer template row has a textbox in each column.
2. I want the two footer rows filled in with data. These are not subtotals;
they come from a different calculated datasource.

From To Percent
01/01/2002 12/31/2002 10
01/01/2003 12/31/2003 15
01/01/2003 11/30/2004 20
------------------------------------
Cumulative 11/30/2004 45
Annualized 11/30/2004 15

The data for the two footer rows comes from a two row SQL datasource built
in the dg_ItemBound handler.

3. The itembound handler is supposed to fill in the two footer rows by
checking item type for 'footer' and a footer flag to see whether footer1 or
footer2 is being bound. Depending on which footer row it is, Record 1 or
Record 2 of the datasource is used.

4. PROBLEM: Footer1 'Cumulative' line fills in perfectly, but I'm not
getting Footer2.

5. QUESTION: If there is more than one footer template row, will binding
process keep going beyond first footer row, or does it stop, assuming there
is only one footer row? Or is there something wrong with the code below in
handling the two footer rows?

6. If it is not possible to accomplish my goal this way, is the an
alternative of adding the two footer rows in code after main part of
datagrid is bound?

Thanks very much for looking at this.

Alan


Code
----------------------------------------------------------------------------
-------------------------------------------
protected void dgManagerPerformance_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{

// Bind footer text

if(e.Item.ItemType == ListItemType.Footer)

{

// Bind Manager Performance footer

// Create connection

string strConnection =
ConfigurationSettings.AppSettings["ConnectionString"];

SqlConnection cnn = new SqlConnection(strConnection);

cnn.Open();

// Create command

string strSQL = ("SELECT * FROM dbo.fn_GetCumulativeAnnualPerformance(6512,
'NIKK', 'SP50')");

SqlCommand cmd = new SqlCommand(strSQL, cnn);

// Create data adapter and fill dataset)

SqlDataAdapter daManagerPerformanceFooter = new SqlDataAdapter(cmd);

DataSet dsManagerPerformanceFooter = new DataSet();

daManagerPerformanceFooter.Fill(dsManagerPerformanceFooter);

cnn.Close();

// Check flag for footer1 or footer2


if(Session["footerFlag"] == null)

{

// Bind Cumulative footer1 columns to datasource

e.Item.Cells[1].Text =
DateTime.Parse(dsManagerPerformanceFooter.Tables[0].Rows[0]
["StartDate"].ToString()).ToShortDateString();

e.Item.Cells[3].Text
=DateTime.Parse(dsManagerPerformanceFooter.Tables[0].Rows[0]
["EndDate"].ToString()).ToShortDateString();

e.Item.Cells[4].Text = String.Format("{0:#,##0.00}",
dsManagerPerformanceFooter.Tables[0].Rows[0] ["MgrPct"]);

e.Item.Cells[5].Text = String.Format("{0:#,##0.00}",
dsManagerPerformanceFooter.Tables[0].Rows[0] ["IndexAPct"]);

e.Item.Cells[6].Text = String.Format("{0:#,##0.00}",
dsManagerPerformanceFooter.Tables[0].Rows[0] ["IndexBPct"]);

dgManagerPerformance.FindControl["txtToFooter1"].Text = "XXX";

Session.Add("footerFlag", "footerRow2");

}

else if (Session["footerFlag"] == "footerRow2")

{

// Bind Annualized footer2 columns to datasource

e.Item.Cells[1].Text =
DateTime.Parse(dsManagerPerformanceFooter.Tables[0].Rows[1]
["StartDate"].ToString()).ToShortDateString();

e.Item.Cells[3].Text
=DateTime.Parse(dsManagerPerformanceFooter.Tables[0].Rows[1]
["EndDate"].ToString()).ToShortDateString();

e.Item.Cells[4].Text = String.Format("{0:#,##0.00}",
dsManagerPerformanceFooter.Tables[0].Rows[1] ["MgrPct"]);

e.Item.Cells[5].Text = String.Format("{0:#,##0.00}",
dsManagerPerformanceFooter.Tables[0].Rows[1] ["IndexAPct"]);

e.Item.Cells[6].Text = String.Format("{0:#,##0.00}",
dsManagerPerformanceFooter.Tables[0].Rows[1] ["IndexBPct"]);

Session.Add("footerFlag", null);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top