hello sir
i am using jquery for textboxvalue auto sum and show in lbltotalprice but when i saved in databse value not save in database please guide me
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="http://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
//Iterate through each Textbox and add keyup event handler
$(".clsTxtToCalculate").each(function () {
$(this).keyup(function () {
//Initialize total to 0
var total = 0;
$(".clsTxtToCalculate").each(function () {
// Sum only if the text entered is number and greater than 0
if (!isNaN(this.value) && this.value.length != 0) {
total += parseFloat(this.value);
}
});
//Assign the total to label
//.toFixed() method will roundoff the final sum to 2 decimal places
$('#<%=lblTotalPrice.ClientID %>').html(total.toFixed(2));
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<fieldset style="width: 315px;">
<legend>Running Total of all TextBoxes</legend>
<table border="1px" cellpadding="5" style="border-collapse: collapse;">
<tr>
<td>
1
</td>
<td>
Milk:
</td>
<td>
<asp:TextBox ID="txtMilk" CssClass="clsTxtToCalculate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
2
</td>
<td>
Bread:
</td>
<td>
<asp:TextBox ID="txtBread" CssClass="clsTxtToCalculate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
3
</td>
<td>
Noodles:
</td>
<td>
<asp:TextBox ID="txtNoodles" CssClass="clsTxtToCalculate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
4
</td>
<td>
Cheese:
</td>
<td>
<asp:TextBox ID="txtCheese" CssClass="clsTxtToCalculate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<b>Total Price</b>
</td>
<td>
<asp:Label ID="lblTotalPrice" runat="server"></asp:Label>
</td>
</tr>
</table>
</fieldset>
</div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.IO;
public partial class textboxsum : System.Web.UI.Page
{
SqlCommand cmd;
SqlConnection con;
SqlDataAdapter adp;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconn1"].ConnectionString);
if (!IsPostBack)
{
}
} protected void Button1_Click(object sender, EventArgs e)
{
cmd = new SqlCommand("insert into sumvalue(totalvalue) values (@totalvalue) ", con);
con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@totalvalue", lblTotalPrice.Text);
cmd.ExecuteNonQuery();
con.Close();
}
}
Data base
autoid int Unchecked
totalvalue nvarchar(MAX) Checked