Multiple Footer Rows

Discussion in 'ASP .Net Datagrid Control' started by Alan Z. Scharf, Nov 27, 2004.

  1. 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);

    }
    Alan Z. Scharf, Nov 27, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schultz
    Replies:
    1
    Views:
    504
    Karl Seguin
    Feb 14, 2005
  2. Subba Rao via DotNetMonster.com

    script for moving rows up and down and traverse thru rows of HTML table

    Subba Rao via DotNetMonster.com, Mar 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    8,197
    Subba Rao via DotNetMonster.com
    Mar 19, 2005
  3. helpful sql
    Replies:
    0
    Views:
    795
    helpful sql
    May 19, 2005
  4. Henrik
    Replies:
    1
    Views:
    416
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
  5. Melvyn

    Datagrid Footer - Multiple rows

    Melvyn, Dec 9, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    138
    Melvyn
    Dec 9, 2003
Loading...

Share This Page