Hi smile,
Refer below sample.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ShowFooter="true">
<Columns>
<asp:BoundField DataField="ItemCode" HeaderText="Code" />
<asp:BoundField DataField="Item" HeaderText="Item" />
<asp:BoundField DataField="Price" HeaderText="Price" ItemStyle-CssClass="price" />
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server" Text="0"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<b>Grand Total: </b>
<asp:Label ID="lblGrandTotal" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<label class="control-label" style="margin-top: 10px; color: Green; font-size: large;
font-weight: bolder; font-style: oblique;">
Sub Total:</label>
<asp:Label ID="lblGrant" runat="server" Text="0" class="control-label" Style="margin-top: 10px;
color: Red; font-size: large; font-weight: bolder; font-style: italic;"></asp:Label>
<asp:HiddenField ID="hfGrantTotal" runat="server" />
<div class="col-sm-3">
<asp:UpdatePanel ID="SCPanelDis" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<label class="control-label" style="margin-top: 10px;">
Discount</label>
<asp:TextBox ID="txtDis" runat="server" class="form-control" Font-Size="Large" Font-Bold="true"
placeholder="0" AutoPostBack="true" OnTextChanged="UpdateDis_Text"></asp:TextBox>
<label class="control-label" style="margin-top: 10px;">
Total Bill</label>
<asp:TextBox ID="txtGTotal" runat="server" class="form-control" Font-Size="Large"
Font-Bold="true" placeholder="0" ReadOnly="True"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=txtQuantity]").val("0");
});
$("body").on("change keyup", "[id*=txtQuantity]", function () {
var quantity = parseFloat($.trim($(this).val()));
if (isNaN(quantity)) {
quantity = 0;
}
$(this).val(quantity);
var row = $(this).closest("tr");
$("[id*=lblTotal]", row).html(parseFloat($(".price", row).html()) * parseFloat($(this).val()));
var grandTotal = 0;
$("[id*=lblTotal]").each(function () {
grandTotal = grandTotal + parseFloat($(this).html());
});
$('#GridView1').find('tr:has(td)').find('[id*=lblGrandTotal]')[0].innerHTML = grandTotal;
$("[id*=lblGrant]").html(grandTotal);
$("[id*=hfGrantTotal]").val(grandTotal);
});
</script>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("ItemCode"), new DataColumn("Item"), new DataColumn("Price") });
dt.Rows.Add(1, "Shirt", 200);
dt.Rows.Add(2, "Football", 30);
dt.Rows.Add(3, "Bat", 22.5);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void UpdateDis_Text(object sender, EventArgs e)
{
double dicsount = Convert.ToDouble(txtDis.Text);
double subtotal = Convert.ToDouble(hfGrantTotal.Value);
double totalbill = (subtotal * dicsount) / 100;
txtGTotal.Text = totalbill.ToString();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("ItemCode"), New DataColumn("Item"), New DataColumn("Price")})
dt.Rows.Add(1, "Shirt", 200)
dt.Rows.Add(2, "Football", 30)
dt.Rows.Add(3, "Bat", 22.5)
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub UpdateDis_Text(ByVal sender As Object, ByVal e As EventArgs)
Dim dicsount As Double = Convert.ToDouble(txtDis.Text)
Dim subtotal As Double = Convert.ToDouble(hfGrantTotal.Value)
Dim totalbill As Double = (subtotal * dicsount) / 100
txtGTotal.Text = totalbill.ToString()
End Sub
Screenshot