I have the following Code
problem is that why the textbox inside gridview under column RemBal becomes disappear?
Moreover the value of RemBal are not saving in the database. how to fix it?
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=txtPaid]").keyup(function () {
var rowtotal = $(this).closest('tr').find('[id*=txtNet]').val();
var paid = $(this).val();
$(this).closest('tr').find('[id*=txtRem]').val(parseFloat(rowtotal) - parseFloat(paid));
});
$(".field1").keyup(function () {
var total = 0;
$(".field1").each(function () {
total *= parseFloat($(this).val());
});
$(".totaloffield td").eq(1).text(total);
//calculate total for current row
var val1 = $(this).val() == "" ? 0 : $(this).val();
var val2 = $(this).parent().parent().find(".field2").val() == "" ? 0 : $(this).parent().parent().find(".field2").val();
var val3 = $(this).parent().parent().find(".field3").val() == "" ? 0 : $(this).parent().parent().find(".field3").val();
var rowtotal = parseFloat(!isNaN(val1) ? val1 : 0) + parseFloat(!isNaN(val2) ? val2 : 0) - parseFloat(!isNaN(val3) ? val3 : 0);
$(this).parent().siblings().last().text(rowtotal);
$(this).closest('tr').find('[id*=txtRem]').val(rowtotal);
});
$(".field2").keyup(function () {
var total = 0;
$(".field2").each(function () {
total *= parseFloat($(this).val());
});
$(".totaloffield td").eq(6).text(total);
//calculate total for current row
var val1 = $(this).parent().parent().find(".field1").val() == "" ? 0 : $(this).parent().parent().find(".field1").val();
var val2 = $(this).val() == "" ? 0 : $(this).val();
var val3 = $(this).parent().parent().find(".field3").val() == "" ? 0 : $(this).parent().parent().find(".field3").val();
var rowtotal = parseFloat(!isNaN(val1) ? val1 : 0) * parseFloat(!isNaN(val2) ? val2 : 0) - parseFloat(!isNaN(val3) ? val3 : 0);
$(this).parent().siblings().last().text(rowtotal);
$(this).closest('tr').find('[id*=txtNet]').val(rowtotal);
});
$(".field3").keyup(function () {
var total = 0;
$(".field3").each(function () {
total += parseFloat($(this).val());
});
$(".totaloffield td").eq(7).text(total);
//calculate total for current row
var val1 = $(this).parent().parent().find(".field1").val() == "" ? 0 : $(this).parent().parent().find(".field1").val();
var val2 = $(this).parent().parent().find(".field2").val() == "" ? 0 : $(this).parent().parent().find(".field2").val();
var val3 = $(this).val() == "" ? 0 : $(this).val();
var rowtotal = parseFloat(!isNaN(val1) ? val1 : 0) * parseFloat(!isNaN(val2) ? val2 : 0) - parseFloat(!isNaN(val3) ? val3 : 0);
$(this).parent().siblings().last().text(rowtotal);
$(this).closest('tr').find('[id*=txtNet]').val(rowtotal);
});
$(".field5").keyup(function () {
var total = 0;
$(".field5").each(function () {
total += parseFloat($(this).val());
});
$(".totaloffield td").eq(8).text(total);
//calculate total for current row
var val1 = $(this).parent().parent().find(".field4").val() == "" ? 0 : $(this).parent().parent().find(".field4").val();
var val2 = $(this).parent().parent().find(".field5").val() == "" ? 0 : $(this).parent().parent().find(".field5").val();
var val3 = $(this).val() == "" ? 0 : $(this).val();
var rowtotal = parseFloat(!isNaN(val1) ? val1 : 0) - parseFloat(!isNaN(val2) ? val2 : 0);
$(this).parent().siblings().last().text(rowtotal);
$(this).closest('tr').find('[id*=txtRem]').val(rowtotal);
});
})
</script>
<asp:GridView ID="GridView1" runat="server" AllowPaging="false" Class="table table-striped table-bordered table-hover"
AutoGenerateColumns="false" RowStyle-Wrap="false" HeaderStyle-Wrap="true">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="checkAll" runat="server" onclick="checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="Check_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product ID" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label ID="lblCode" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="200px" DataField="P_Type" HeaderText="Product Category" />
<asp:BoundField ItemStyle-Width="200px" DataField="P_Name" HeaderText="Product Name" />
<asp:TemplateField>
<HeaderTemplate>
Quantity</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" Text="0" class="field1 form-control"
Width="100"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Rate</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtRate" runat="server" Text="0" class="field2 form-control" Width="100"
ItemStyle-CssClass="price"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Discount</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtDiscount" runat="server" Text="0" class="field3 form-control"
Width="100" ItemStyle-CssClass="discount"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Net Balance</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtNet" runat="server" Text="0" class="field4 form-control" Width="100"
ItemStyle-CssClass="pay"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Paid</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtPaid" runat="server" Text="0" class="field5 form-control" Width="100"
ItemStyle-CssClass="paid"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
RemBal</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtRem" runat="server" Text="0" class="field6 form-control" Width="100"
ItemStyle-CssClass="rem"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
foreach (GridViewRow gvrow in GridView1.Rows)
{
CheckBox chck = gvrow.FindControl("CheckBox1") as CheckBox;
if (chck.Checked)
{
con = new SqlDbConnect();
string Inv = txtInv.Text.Trim();
string Cat = ddlHead.SelectedValue.ToString();
string Ven = ddlVendor.SelectedValue.ToString();
string date = txtDate.Text.Trim();
string PId = (gvrow.FindControl("lblCode") as Label).Text;
string Qty = (gvrow.FindControl("txtQuantity") as TextBox).Text;
string Rate = (gvrow.FindControl("txtRate") as TextBox).Text;
string Discount = (gvrow.FindControl("txtDiscount") as TextBox).Text;
string Net = (gvrow.FindControl("txtNet") as TextBox).Text;
string Paid = (gvrow.FindControl("txtPaid") as TextBox).Text;
string Rem = (gvrow.FindControl("txtRem") as TextBox).Text;
con.SqlQuery("INSERT INTO tblPurchase (InvoiceNo,P_Date,VendorID,ProID,ProductID,Quantity,Price,Discount,NetBal,Paid,RemBal) VALUES (@No,@Date,@VId,@PrId,@PId,@Qty,@Rate,@Dis,@Net,@Paid,@Rem)");
con.Cmd.Parameters.AddWithValue("@No", Inv);
con.Cmd.Parameters.AddWithValue("@PrId", Cat);
con.Cmd.Parameters.AddWithValue("@VId", Ven);
con.Cmd.Parameters.AddWithValue("@Date", date.ToString());
con.Cmd.Parameters.AddWithValue("@PId", PId);
con.Cmd.Parameters.AddWithValue("@Qty", Qty);
con.Cmd.Parameters.AddWithValue("@Rate", Rate);
con.Cmd.Parameters.AddWithValue("@Dis", Discount);
con.Cmd.Parameters.AddWithValue("@Net", Net);
con.Cmd.Parameters.AddWithValue("@Paid", Paid);
con.Cmd.Parameters.AddWithValue("@Rem", Rem);
con.NonQueryEx();
con.conClose();
this.VoucherNo();
}
}