I used your below approach, it is working fine, but when i am inserting data into table then txtrate column data is not getting insert into table
Remaining other value are getting inserting into table
<script type="text/javascript">
$(function () {
$("[id*=txtrate]").val("0");
});
$("body").on("change keyup", "[id*=txtrate]", function () {
//Check whether Quantity value is valid Float number.
var rate = parseFloat($.trim($(this).val()));
if (isNaN(rate)) {
rate = 0;
}
//Update the Quantity TextBox.
$(this).val(rate);
//Calculate and update Row Total.
var row = $(this).closest("tr");
$("[id*=lbtotal]", row).html(parseFloat($("td", row).eq(3).html()) * parseFloat($(this).val()));
//Calculate and update Grand Total.
var grandTotal = 0;
$("[id*=lbtotal]").each(function () {
grandTotal = grandTotal + parseFloat($(this).html());
});
$("[id*=lblGrandTotal]").html(grandTotal.toString());
});
</script>
Gridview
Secondary
<asp:GridView ID="gvSelected" runat="server"
AutoGenerateColumns = "false" Font-Names = "Arial"
Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B"
HeaderStyle-BackColor = "green" EmptyDataText = "No Records Selected" OnRowDataBound="gvSelected_RowDataBound" >
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="GRN_DID" HeaderText="ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="GRN_ID" HeaderText="GRN_ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="It_ID" HeaderText="ITID" />
<asp:BoundField ItemStyle-Width="150px" DataField="It_Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="grn_qty" HeaderText="QTY" />
<asp:TemplateField HeaderText="Rate" >
<ItemTemplate>
<asp:TextBox ID="txtrate" runat="server" Width="50px" Text='<%#Eval("txtrate")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total" >
<ItemTemplate>
<asp:Label ID="lbtotal" runat="server" Width="50px" Text='<%#Bind("lbtotal")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C#
protected void btn_sv_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)ViewState["SelectedRecords"];
string gRN_DID, gRN_ID, it_Name, grn_qty, it_ID, xtrate;
int ResultValue = 0;
foreach (DataRow row in dt.Rows)
{
gRN_DID = (row["GRN_DID"].ToString());
gRN_ID = (row["GRN_ID"].ToString());
it_Name = (row["It_Name"].ToString());
grn_qty = (row["Grn_qty"].ToString());
xtrate = (row["txtrate"].ToString());
it_ID = (row["It_ID"].ToString());
ResultValue += this.InsertRows(gRN_DID, gRN_ID, it_Name, grn_qty, xtrate, it_ID);
}
if (ResultValue == dt.Rows.Count)
{
// Response.Redirect("impprnt.aspx?I_ID=" + I_ID + "");
}
else
{
// string Url = "grnprint.aspx?I_ID=" + lblast.Text;
// Response.Write("<script language='javascript'>window.open('" + Url + "','_blank','');");
Response.Write("</script>");
string message = "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);
}
}
private int InsertRows(string gRN_DID, string gRN_ID, string it_Name, string grn_qty, string xtrate, string it_ID)
{
using (SqlCommand cmd = new SqlCommand("Sp_InsertDetail", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@GRN_DID", gRN_DID);
cmd.Parameters.AddWithValue("@GRN_ID", gRN_ID);
cmd.Parameters.AddWithValue("@It_ID", it_ID);
cmd.Parameters.AddWithValue("@GRN_qty", grn_qty);
cmd.Parameters.AddWithValue("@xtrate", xtrate);
con.Open();
int ResultValue = cmd.ExecuteNonQuery();
con.Close();
return ResultValue;
}
}