View Single Post
  #2 (permalink)  
Old April 3rd, 2008, 02:25 PM
weicco weicco is offline
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can't you count subtotals in SQL query? Just add field to your query: SELECT *, count(something) FROM Foo; and add new field to gridview.

Or if you can't do that, add new field to gridview, add RowCreated event and writing something like this to the handler:

Code:
void GridView1_RowCreated(Object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        int columnIndex = e.Row.Cells.Count - 1; // Last cell
        int ctrlIndex = 0; // I think zero is the correct value ...
                           // If not, try 1

        Label label = e.Row.Cells[columnIndex].Controls[ctrlIndex] as Label;
        GridViewRow container = label.NamingContainer as GridViewRow;

        // You can use DataBinder to evaluate datasource's values
        int hours = (int)DataBinder.Eval(container, "Hours");

        // Do your stuff here
        int subTotal = count_subtotal_orwhatever();

        // And we're done!
        label.Text = subTotal.ToString();
    }
}
Reply With Quote