Column toal in webgrid footer

Legacy

A description has not yet been added to this group.

Column toal in webgrid footer

  • rated by 0 users
  • This post has 2 Replies |
  • 2 Followers
  • Hello friends,

    Can anybody tell how to display the column totals in each column's footer. i.e each columns total should display in its corresponding footer column. When I tried, it is display above the footer and also it is aligned left. I want the total to be displayed exactly below each column.

    Please help.

    Thanks in advance 

  • Hello,

    I was able to do this as follows:

             protected void Page_Load(object sender, EventArgs e)
            {
                C1WebGrid1.ShowFooter = true;
                C1WebGrid1.DataBound += (newSender, newE) =>
                {
                    int total = 0;

                    for (int i = 0; i < C1WebGrid1.Items.Count; i++)
                    {
                        total += int.Parse(C1WebGrid1.Items[i].Cells[0].Text);
                    }

                    C1WebGrid1.Columns[0].FooterText = total.ToString();
                    C1WebGrid1.Columns[1].FooterText = C1WebGrid1.Items.Count.ToString();
                    C1WebGrid1.Columns[2].FooterText = C1WebGrid1.Items.Count.ToString();
                };
            }

    How were you handling this?  Also, please let me know if you have any questions.

    Regards,

    -Raleigh

  •  Thanks Raleigh for the reply

     I solved it in the following way which I got from the post

    http://forums.componentone.com/CS/forums/p/69297/190351.aspx#190351

     --------------------------------------------

    private C1GridItem footer = null;
    private int sum = 0;
     
    //memorize footer row.
    protected void C1WebGrid1_ItemCreated(object sender, C1ItemEventArgs e)
    {
      if (e.Item.ItemType == C1ListItemType.Footer)
        footer = e.Item;
    }
     
    //summarize the values from third column.
    protected void C1WebGrid1_ItemDataBound(object sender, C1ItemEventArgs e)
    {
      sum += int.Parse(e.Item.Cells[2].Text);
    }
     
    //place the result into the third cell of the footer row.
    protected void C1WebGrid1_DataBound(object sender, EventArgs e)
    {
      footer.Cells[2].Text = "Total: " + sum.ToString();
    }

     ----------------------------------

    Thanks a lot for helping me.

    Regards 

    Shivan

     

Page 1 of 1 (3 items)