i have a repeater control that contain 13 rows, from that rows i want to sum(Total) a column in the control. How can i Get total, Anyone please post solution for this.......
Loading
i have a repeater control that contain 13 rows, from that rows i want to sum(Total) a column in the control. How can i Get total, Anyone please post solution for this.......
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Nov 22, 2011, 12:54 AM
Here is your solution
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
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;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand();
SqlConnection con;
string str;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(connStr);
cmd.Connection = con;
cmd.CommandText = "Select * from employee";
con.Open();
r1.DataSource = cmd.ExecuteReader();
r1.DataBind();
con.Close();
}
public string totalsal()
{
SqlConnection con = new SqlConnection(connStr);
str = "SELECT SUM(Salary) from employee";
cmd = new SqlCommand(str, con);
con.Open();
decimal Totalsalary = Convert.ToDecimal(cmd.ExecuteScalar().ToString());
con.Close();
con.Dispose();
cmd.Dispose();
return Convert.ToString(Totalsalary);
}
}
Thanks
If this post helps you mark it as answer