Hi akhter,
Refer below code.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Enabled="false" ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="Libility_ID" Visible="false">
<ItemTemplate>
<asp:Label ID="Li_ID" runat="server" Text='<%#Bind("Li_ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" ID">
<ItemTemplate>
<asp:Label ID="I_ID" runat="server" Text='<%#Bind("I_ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Invocie_Amount">
<ItemTemplate>
<asp:Label ID="I_Amt" runat="server" Text='<%#Bind("I_Amt")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Previous_Balance">
<ItemTemplate>
<asp:Label ID="Previous_Balance" runat="server" Text='<%#Bind("Previous_Balance")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=" Cheque_NO">
<ItemTemplate>
<asp:TextBox ID="C_NO" runat="server" ReadOnly="true" Text='<%#Bind("C_NO")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Received_Amount">
<ItemTemplate>
<asp:TextBox ID="C_Amt" runat="server" ReadOnly="false" Text='<%#Bind("C_Amt")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current_Balance">
<ItemTemplate>
<asp:TextBox ID="I_Balance" runat="server" ReadOnly="true" Text='<%#Bind("I_Balance")%>'></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblGrandTotal" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:DropDownList ID="ddlStatus" runat="server">
<asp:ListItem Text="Pending" Value="1"></asp:ListItem>
<asp:ListItem Text="Received" Value="2"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var grandTotal = 0;
var grid = document.getElementById('<%=GridView1.ClientID%>');
var tr = grid.getElementsByTagName("tr");
var sum = 0;
for (var i = 1; i < tr.length - 1; i++) {
var iAmount = tr[i].getElementsByTagName("td")[1].getElementsByTagName('span')[0].innerHTML;
var cAmount = tr[i].getElementsByTagName("td")[4].getElementsByTagName('input')[0].value;
var balance = parseFloat(iAmount) - parseFloat(cAmount);
tr[i].getElementsByTagName("td")[5].getElementsByTagName('input')[0].value = balance;
grandTotal += balance;
}
$("[id*=lblGrandTotal]").html(grandTotal.toString());
});
</script>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] {
new System.Data.DataColumn("Li_ID", typeof(int)),
new System.Data.DataColumn("I_ID", typeof(int)),
new System.Data.DataColumn("I_Amt", typeof(int)),
new System.Data.DataColumn("Previous_Balance", typeof(int)),
new System.Data.DataColumn("C_NO", typeof(int)),
new System.Data.DataColumn("C_Amt", typeof(int)),
new System.Data.DataColumn("I_Balance", typeof(int))});
dt.Rows.Add(21, 21, 339, 100, 123, 100, 0);
dt.Rows.Add(22, 22, 622, 100, 123, 100, 0);
dt.Rows.Add(23, 23, 226, 100, 123, 100, 0);
dt.Rows.Add(26, 26, 339, 100, 123, 100, 0);
dt.Rows.Add(27, 27, 339, 100, 123, 100, 0);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn() {
New System.Data.DataColumn("Li_ID", GetType(Integer)),
New System.Data.DataColumn("I_ID", GetType(Integer)),
New System.Data.DataColumn("I_Amt", GetType(Integer)),
New System.Data.DataColumn("Previous_Balance", GetType(Integer)),
New System.Data.DataColumn("C_NO", GetType(Integer)),
New System.Data.DataColumn("C_Amt", GetType(Integer)),
New System.Data.DataColumn("I_Balance", GetType(Integer))})
dt.Rows.Add(21, 21, 339, 100, 123, 100, 0)
dt.Rows.Add(22, 22, 622, 100, 123, 100, 0)
dt.Rows.Add(23, 23, 226, 100, 123, 100, 0)
dt.Rows.Add(26, 26, 339, 100, 123, 100, 0)
dt.Rows.Add(27, 27, 339, 100, 123, 100, 0)
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub