0
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(); 
      }
}
2
Contributors
6
Replies
12
Views
3 Years
Discussion Span
Last Post by japhta
0

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?

0

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

0

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">
                                        <Columns>
                                            <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" >
                                                <ItemTemplate>
                                                    <asp:Label ID="lblWeigh" runat="server" Text='<%# Eval("Weighting") %>'/>
                                                </ItemTemplate>
                                                <FooterTemplate>
                                                    <asp:Label ID ="lblTotalPercentage" runat="server" />
                                                </FooterTemplate>
                                            </asp:TemplateField>

                                        </Columns>

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

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

0

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.