Dear Friends,
I have a Gridview name GridPODetails, in which there is a column named
"Total", whatever the amount is in the total column its sum should be shown in that column but in the Last row or can say bottom of the column.
eg: Total
200
500
--------------
700
how i can achieve this?
Regards,
Aamir
Loading

Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 2, 2012, 7:31 PM EDT
You can achieve this by using ItemTemplate (FooterTemplate) and RowBound event.
Please Refer below link for example.
http://csharpdotnetfreak.blogspot.com/2009/07/display-total-in-gridview-footer.html
http://www.dotnettwitter.com/2012/04/running-total-and-grand-total-in-grid.html
hope this will help you.
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 2, 2012, 9:08 PM EDT
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Sub_total_gridview._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Sub_total_gridview
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
void bind()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from test";
com =new SqlCommand(str, con);
sqlda = new SqlDataAdapter(str, con);
ds =new DataSet();
sqlda.Fill(ds, "test");
GridView1.DataSource = ds;
GridView1.DataMember = "test";
GridView1.DataBind();
con.Close();
}
public string totalbills()
{
SqlConnection con = new SqlConnection(strConnString);
str = "SELECT SUM(bill) from test";
com = new SqlCommand(str, con);
con.Open();
decimal Totalbill = Convert.ToDecimal(com.ExecuteScalar());
con.Close();
con.Dispose();
com.Dispose();
return string.Format(Totalbill.ToString());
}
protected void Page_Load(object sender, EventArgs e)
{
bind();
}
}
}
Thanks
Norberto Flogar16 reputationPosted Jul 2, 2012, 9:52 PM EDT
You can achieve this using ItemCell Changed event of a gridview
Thanks
Wall Stickers
Aamir KhanRank #7,345 · 243 reputationPosted Jul 3, 2012, 1:10 AM EDT
evan croby2 reputationPosted Mar 4, 2014, 7:58 PM EST
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblqy = (Label)e.Row.FindControl("lblqty");
int qty = Int32.Parse(lblqy.Text );
total = total + qty;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotalqty = (Label)e.Row.FindControl("lblTotalqty");
lblTotalqty.Text = total.ToString();
}
}
http://asp.net-informations.com/gridview/gridview-summary.htm
Evan