public void kraGridView_RowDataBound(object sender, GridViewRowEventArgs e)

        int totalPercent = 0;
      if (e.Row.RowType == DataControlRowType.DataRow)
          Label lblWeigh = (Label)e.Row.FindControl("lblWeigh");
         // totalPercent += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "lblWeigh"));
         int total = int.Parse(lblWeigh.Text);
        totalPercent += total;
      else if (e.Row.RowType == DataControlRowType.Footer)
          Label lblTotalPercentage = (Label)e.Row.FindControl("lblTotalPercentage");
         // e.Row.Cells[5].Text = totalPercent.ToString();
          lblTotalPercentage.Text = totalPercent.ToString(); 
4 Years
Discussion Span
Last Post by japhta

Can you elaborate a bit more on what you need help with? Do you have a specific question, or is there an error you are having a problem with?


im trying to calculate a column in grid view, i'm retrieving the data from the database and i'm trying to get the sum of the column and place it on the grid view footer, now the code above is not calculating the sum


this here is my asp.net

<asp:GridView ID="kraGridView" runat="server" AutoGenerateColumns="False" 
                                        BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center" 
                                        onprerender="kraGridView_PreRender" onrowcreated="kraGridView_RowCreated" 
                                        ShowFooter="True" Width="806px" onrowdatabound="kraGridView_RowDataBound">
                                            <asp:BoundField DataField="Measure" FooterText="Grand Total" 
                                                HeaderText="Measure" />
                                            <asp:BoundField DataField="Indicator" HeaderText="Indicator" />
                                            <asp:BoundField DataField="Objective" HeaderText="Objective" />
                                            <asp:BoundField DataField="Description" HeaderText="Description" />

                                            <asp:TemplateField HeaderText ="Weighting" >
                                                    <asp:Label ID="lblWeigh" runat="server" Text='<%# Eval("Weighting") %>'/>
                                                    <asp:Label ID ="lblTotalPercentage" runat="server" />


                                        <FooterStyle BackColor="White" Font-Bold="True" ForeColor="Black"/>
                                        <HeaderStyle Font-Size="12pt" ForeColor="White" />
                                        <RowStyle BorderStyle="Double" />

Yeah, and other articles, but i cant seem to get the sum of my "Weighting" Total on the footer


Hey Guys, finally got it, with the code below, thanks for the assistance

public partial class _Default : System.Web.UI.Page 
    decimal grdTotal = 0;
    protected void Page_Load(object sender, EventArgs e)

protected void GridView1_RowDataBound
                   (object sender, GridViewRowEventArgs e)
 if (e.Row.RowType == DataControlRowType.DataRow)
  decimal rowTotal = Convert.ToDecimal
              (DataBinder.Eval(e.Row.DataItem, "Amount"));
  grdTotal = grdTotal + rowTotal;
 if (e.Row.RowType == DataControlRowType.Footer)
  Label lbl = (Label)e.Row.FindControl("lblTotal");
  lbl.Text = grdTotal.ToString("c");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.