How to calculate Total price on textbox change
event in Gridview.
Step 1 : Apply JavaScript code under a <head > tag.
<script
type="text/javascript">
function
CalcSellPrice2(CurrentPrice, QuntValue, TotalValue) {
var QuntVar =
parseFloat(document.getElementById(QuntValue).value);
var TotalVar =
document.getElementById(TotalValue);
var TotalPriceValue =
parseFloat(CurrentPrice * QuntVar);
TotalVar.innerHTML = TotalPriceValue;
}
</script>
Step 2 : Grid View Source Code.
<asp:GridView
ID="GridView1" runat="server"
AutoGenerateColumns="False"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField
HeaderText="List Price"
Visible="True">
<ItemTemplate>
<asp:Label
ID="lblCurrentListPrice"
runat="server"
Text='<%#
Eval("Price") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="Qunt">
<ItemTemplate>
<asp:TextBox
ID="txtqut"
Width="100px"
runat="Server"
/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField
HeaderText="Total
Price">
<ItemTemplate>
<asp:Label
ID="lblTotal"
runat="Server"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

sPosted Sep 4, 2012, 5:06 AM
Hello, can you please explain how I can add to your example an amount total? I mean, if the user choose few rows and I calculate the sum of each row, how can I calculate the total sum of all the rows and display it in the grid view and in lable? thanks.
sPosted Sep 4, 2012, 5:06 AM
Hello, can you please explain how I can add to your example an amount total? I mean, if the user choose few rows and I calculate the sum of each row, how can I calculate the total sum of all the rows and display it in the grid view and in lable? thanks.
sPosted Sep 4, 2012, 5:06 AM
Hello, can you please explain how I can add to your example an amount total? I mean, if the user choose few rows and I calculate the sum of each row, how can I calculate the total sum of all the rows and display it in the grid view and in lable? thanks.