C1 Community
ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Column toal in webgrid footer

rated by 0 users
This post has 2 Replies | 2 Followers

Not Ranked
Posts 7
cvshivan Posted: Tue, Jan 19 2010 8:00 AM

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 

Top 25 Contributor
Posts 372

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

Not Ranked
Posts 7
cvshivan replied on Thu, Jan 21 2010 11:42 PM

 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) | RSS
Contact ComponentOne: 1.800.858.2739 ©1987-2010 ComponentOne LLC All Rights Reserved.