Hi smile,
Check this example. Now please take its reference and correct your code.
HTML
<div>
<%@ register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<cc1:ToolkitScriptManager runat="server">
</cc1:ToolkitScriptManager>
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
CssClass="table table-striped table-bordered table-hover" AutoGenerateColumns="false"
Width="100%">
<Columns>
<asp:TemplateField HeaderText="Product Code" ItemStyle-Width="150">
<ItemTemplate>
<asp:Label ID="lblCode" runat="server" Text='<%# Eval("ItemCode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ItemName" HeaderText="Product Name" ItemStyle-Width="200px" />
<asp:BoundField DataField="Rate" HeaderText="Price" ItemStyle-CssClass="price" ItemStyle-Width="100px" />
<asp:TemplateField HeaderText="Quantity" ItemStyle-Width="300px">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" Text="0" class="form-control" Width="100px"></asp:TextBox>
<cc1:NumericUpDownExtender ID="nudeQuantity" runat="server" TargetControlID="txtQuantity"
Width="50" Enabled="True" Minimum="0" TargetButtonUpID="btnAdd" TargetButtonDownID="btnSub">
</cc1:NumericUpDownExtender>
<asp:Button ID="btnAdd" Text="Add" Class="btn btn-info" runat="server" />
<asp:Button ID="btnSub" Text="Sub" Class="btn btn-info" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total" ItemStyle-Width="200px">
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server" Text="0"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ButtonType="Button" ControlStyle-CssClass="btn btn-danger" />
</Columns>
</asp:GridView>
</div>
<div>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<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*=btnAdd] [id*=btnSub]').on("click", function () {
var quantity = $(this).closest('tr').find('[id*=txtQuantity]').val();
if (isNaN(parseInt(quantity))) {
var price = $(this).closest('tr').find('td').eq(2).html();
var total = parseFloat(price) * (parseFloat(quantity));
$(this).closest('tr').find('[id*=lblTotal]').html(total);
}
});
$("[id*=txtQuantity]").on("change keyup", function () {
if (!isNaN(parseInt($(this).val()))) {
var price = $(this).closest('tr').find('td').eq(2).html();
var quantity = $(this).val();
var total = parseFloat(price) * parseFloat(quantity);
$(this).closest('tr').find('[id*=lblTotal]').html(total);
}
});
});
</script>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("ItemCode", typeof(string)),
new DataColumn("ItemName", typeof(string)),
new DataColumn("Rate",typeof(string)) });
dt.Rows.Add("R-000003", "Pencil", "200");
dt.Rows.Add("R-000001", "Islamiate", "100");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
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", GetType(String)), New DataColumn("ItemName", GetType(String)), New DataColumn("Rate", GetType(String))})
dt.Rows.Add("R-000003", "Pencil", "200")
dt.Rows.Add("R-000001", "Islamiate", "100")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Screenshot