Dear Sir,
Please help me make a function of sum count of textbox values.
Sum Values not in display TextBox11
namespace BPM
{
public partial class vw : System.Web.UI.Page
{
int empno = 0;
protected void Page_Load(object sender, EventArgs e)
{
empno = Convert.ToInt32(Request.QueryString["Id"].ToString());
Session["EmpId"] = empno;
if (!IsPostBack)
{
BindTextBoxvalues();
BindGrid();
}
}
private void BindTextBoxvalues()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("select * from bpms where Id=" + empno, con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Label1.Text = dt.Rows[0][0].ToString();
Label3.Text = dt.Rows[0][1].ToString();
Label2.Text = dt.Rows[0][2].ToString();
Label13.Text = dt.Rows[0][3].ToString();
Label4.Text = dt.Rows[0][4].ToString();
Label5.Text = dt.Rows[0][5].ToString();
Label6.Text = dt.Rows[0][6].ToString();
Label7.Text = dt.Rows[0][7].ToString();
Label8.Text = dt.Rows[0][8].ToString();
Label9.Text = dt.Rows[0][9].ToString();
Label10.Text = dt.Rows[0][10].ToString();
Label11.Text = dt.Rows[0][11].ToString();
// Label12.Text = dt.Rows[0][3].ToString();
}
private void calcualtion()
{
int num1 = Int32.Parse(TextBox3.Text);
int num2 = Int32.Parse(TextBox4.Text);
int num3 = Int32.Parse(TextBox5.Text);
int num4 = Int32.Parse(TextBox6.Text);
int num5 = Int32.Parse(TextBox7.Text);
int num6 = Int32.Parse(TextBox8.Text);
int sum = num1 + num2 + num3 + num4 + num5 + num6;
TextBox11.Text = sum.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
//string mrk_in_cisf = DateTime.Now.ToString();
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE bpms SET amt_rls = @amt_rls,amt_rls_dt=@amt_rls_dt,tds_gst=@tds_gst,tds_it=@tds_it,ld=@ld,sd_pbg=@sd_pbg,instl_chrg=@instl_chrg,othr_ded=@othr_ded,othr_ded_rsn=@othr_ded_rsn,gnrl_rmk=@gnrl_rmk WHERE Id = @Id"))
{
cmd.Parameters.AddWithValue("@Id", Label1.Text);
cmd.Parameters.AddWithValue("@amt_rls", TextBox1.Text);
cmd.Parameters.AddWithValue("@amt_rls_dt", TextBox2.Text);
cmd.Parameters.AddWithValue("@tds_gst", TextBox3.Text);
cmd.Parameters.AddWithValue("@tds_it", TextBox4.Text);
cmd.Parameters.AddWithValue("@ld", TextBox5.Text);
cmd.Parameters.AddWithValue("@sd_pbg", TextBox6.Text);
cmd.Parameters.AddWithValue("@instl_chrg", TextBox7.Text);
cmd.Parameters.AddWithValue("@othr_ded", TextBox8.Text);
cmd.Parameters.AddWithValue("@othr_ded_rsn", TextBox9.Text);
cmd.Parameters.AddWithValue("@gnrl_rmk", TextBox10.Text);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
string message = "Bill details have been saved successfully.";
string script = "window.onload = function(){ alert('";
script += message;
script += "');";
script += "window.location = '";
script += Request.Url.AbsoluteUri;
script += "'; }";
ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
}
}
// Response.Redirect("fa.aspx");
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox9.Text = "";
TextBox10.Text = "";
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("fa.aspx");
}
private void BindGrid()
{
//int Id = Convert.ToString(Label1.Text);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM bpms WHERE mrk_in_fa='YES'and Id=" + empno, con);
//SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM bpms WHERE Id='@Id'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Mark(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
int Id = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32((sender as Button).CommandArgument)].Values[0]);
string mrk_in_fa = "NO";
// string mrk_in_fa_dt = DateTime.Now.ToString();
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE bpms SET mrk_in_fa = @mrk_in_fa WHERE Id = @Id"))
{
cmd.Parameters.AddWithValue("@Id", Id);
cmd.Parameters.AddWithValue("@mrk_in_fa", mrk_in_fa);
// cmd.Parameters.AddWithValue("@mrk_in_fa_dt", mrk_in_fa_dt);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
row.Visible = false;
}
}
}
protected void Closed(object sender, EventArgs e)
{
GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
int Id = Convert.ToInt32(GridView1.DataKeys[Convert.ToInt32((sender as Button).CommandArgument)].Values[0]);
string stl = "YES";
// string mrk_in_fa_dt = DateTime.Now.ToString();
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE bpms SET stl = @stl WHERE Id = @Id"))
{
cmd.Parameters.AddWithValue("@Id", Id);
cmd.Parameters.AddWithValue("@stl", stl);
// cmd.Parameters.AddWithValue("@mrk_in_fa_dt", mrk_in_fa_dt);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
row.Visible = false;
}
}
}
}
}