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
evan crobyPosted Mar 5, 2014, 12:58 AM
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
Aamir KhanPosted Jul 3, 2012, 5:10 AM
Norberto FlogarPosted Jul 3, 2012, 1:52 AM
You can achieve this using ItemCell Changed event of a gridview
Thanks
Wall Stickers
Satyapriya NayakPosted Jul 3, 2012, 1:08 AM
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
Jignesh TrivediPosted Jul 2, 2012, 11:31 PM
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.