Kasuni Abegunawardana

Kasuni Abegunawardana

  • NA
  • 211
  • 125.6k

How to calculate( sum) of the data grid column.

Dec 4 2017 12:42 PM
Hi all,
 
I have retreive data to a data grid without sqldatasource.
 
private void BindGrid2()
{
string constr = (ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM OnlineDiary_tb where U_EmailAddress='" + Session["U_Email"].ToString() + "'and Date='"+ DateTime.Today.ToString()+"' ", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView2.DataSource = dt;
GridView2.DataBind();
}
}
}
}
 
Now want to calculate colunm data.
 
Thank you in advance.

Answers (8)