.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

GridView with Javascript calculation

Posted By:      Posted Date: October 17, 2010    Points: 0   Category :ASP.Net

Okay so here's a simple example of what I'm trying to do. I've researched this for days and still haven't found the solution. TextBox1 in this case should show the total for the 8 GridView1 rows(TextBox3). So if I put $22.00 in the first TextBox3 the total should show $22.00  and when I put $2.00 in the next row TextBox3 the Total (TextBox1) should show $24.00. Does anyone know how to do this? The GridView is populated with blank data from SqlDataSource1 -  FName, LName and AGI (income). Any help would be greatly appreciated.

ASPX Code:

    <form id="form1" runat="server">
    <script type="text/javascript">
      function calculateSubTotal()
          var txt1 = document.getElementById("GridView1_ctl02_TextBox3").value;
          var txt2 = document.getElementById("GridView1_ctl03_TextBox3").value;
          var txt3 = document.getElementById("GridView1_ctl04_TextBox3").value;
          var txt4

View Complete Post

More Related Resource Links

JavaScript Calculation in gridview item template with some condition ???


Hi ...

My javascript to calculate gridview columns on gridview databound

<script type="text/javascript" language="javascript">  
    function CalcAmount(quantity1, price1, amount1)
        document.getElementById(amount1).value = parseFloat(document.getElementById(quantity1).value) * parseFloat(document.getElementById(price1).value);  

Gridview Cs code

 protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)

                    if (e.Row.RowType == DataControlRowType.DataRow)
                    TextBox txtQuantity = (TextBox)e.Row.FindControl("TextBox1");
                    TextBox txtPrice = (TextBox)e.Row.FindControl("TextBox34");
                    TextBox txtAmount = (TextBox)e.Row.FindControl("TextBox4");

                    TextBox txtQuantity1 = (TextBox)e.Row.FindControl("TextBox2");
                    TextBox txtPrice1 = (TextBox)e.Row.FindControl("TextBox34");
                    TextBox txtAmount1 = (TextBox)e.Row.FindControl("BP");

                    txtPrice1.Attributes.Add("onkeyup", "CalcAmount('" + txtQuantity.ClientID

Ajax Enabled Gridview using JavaScript in ASP.NET

Before explaining the article, I would like to thank all readers who read my article and voted for it. Your appreciation for my article gives me strength to write more good articles. Hope in future I will get your valuable comments and suggestions. Now I won't waste your time and come back to the topic. I have written this article on 'Ajax Enabled Gridview Using JavaScript in ASP.NET'. In this article, I will show you how to make a Gridview using a simple HTML table, JavaScript and XML HTTP for Ajax call without using any ASP.NET control.

Using Code

GridView Javascript Click Row and Ajax

This article shows 2 common tasks with the ASP.NET GridView: Binding a List (generic) of objects as DataSource and on clicking a row, getting the values of the selected row by a javascript function. In the example a List with User-objects is displayed. On clicking a row containing the data of a User-object, the Id of the object is used to get the address of the user by an Ajax-call and display it in a details-field.

Select all checkboxes in gridview using Javascript


Hello members,


              I have used "Check box" inside the gridview...

              I need,

                           If i select the header check box , It should select all the checkbox inside the gridview...

              I have searched in google for this coding ...I got  lot of codes but couldn't get the correct code...

              I request anyone please provide me the correct code(using Javascript) thanks...

How To Access Datakeys In Javascript...and How To make gridview Column Visible true in javascript


How To Access Gridview's Datakeys In Javascript...and How To make gridview Column Visible true in javascript

Reply me..

validate the selection of atleast one checkbox in the gridview using javascript


 i have a gridview with a checkbox in the templatefield as given  below,

<asp:GridView runat="server" ID="gvAsgnHw"  AutoGenerateColumns="False"   >
        <asp:CheckBox id="cbAsgnHwGrid"   runat="server" /> </ItemTemplate></asp:TemplateField>

         <asp:BoundField DataField="Resource_id" HeaderText="Resource ID"/>
        <asp:BoundField DataField="Resource_name" HeaderText="Hardware Name" />

I want to check the selection of atleast one checkbox on a button click using javascript.
pls help

Calculating GridView total using JavaScript/JQuery


Hello everyone.

One month ago I've had very nice conversation with a asp.net forum member asking about issue regarding calculation of GridView textboxes total using JavaScript. The main thing was to allow user to manually write values in the text boxes (placed inside GridView column) and if the value has changed automatically to perform calculation on client side.

At the end of the conversation, we came up to two solutions. The first solution was using plain JavaScript, but since I thought it was not so robust, and in order to make it more robust we would need to write few more functions. Therefore, I have simply proposed another solution using JQuery which came up much better, more robust with less code.

In this blog post I will show both of the solutions and will provide step by step explanation on how we did that.

Note: I'm using VWD.

how do i use javascript to change values of controls inside a gridview

i have 2 labels (lblRate,lblTotal) and a textbox (txtQuantity) in a itemtemplate of a gridview.I want to calculate the products of rate and quantity and show it in Total as the textbox loses focus...i cant use textchanged because i dont want the page to postback.How do i use javascript to achieve this??Please Help Urgently....<asp:TemplateField HeaderText="Rate">                <ItemTemplate>                    <asp:Label ID="lblRate" runat="server" Text='<%# Eval("Rate") %>' />                </ItemTemplate>            </asp:TemplateField> <asp:TemplateField HeaderText="Quantity">                <ItemTemplate>                    <asp:TextBox ID="txtQty" runat="server" />                </ItemTemplate>&

getting minutes from calculation in gridview

Hi..I have to change the background colour of a calculated field (just the cell not the whole row) in my gridview called ElapsedTime, based on the number of minutes e.g > 30 mins background is red.I have already done something simliar for hours..I have succesfully written a sql statement that calculates elapsed timeCONVERT(Varchar, (DATEPART(dd, GETDATE() - DateAdded)-1) * 24 + DATEPART(hh,GETDATE() - DateAdded)) + 'h:' + CONVERT(Varchar, DATEPART(mi, GETDATE() - DateAdded)) + 'm' AS ElapsedTimeElapsed time looks like this e.g 11h:14mI then used this bit of code to get the hourProtected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound        Dim et As String                ' For Each r As GridViewRow In GridView1.Rows        If e.Row.RowType = DataControlRowType.DataRow Then            et = e.Row.Cells(13).Text            et = et.Substring(0, et.IndexOf("h"))            Dim number As Integer = Int32.Parse(et)            If e.Ro

Validating DropdownList Inside Gridview Using Javascript

hi All,      I have Gridview with Dropdownlist which contains data as {select,1,2,3} .Gridview contains multiple rows of data.Submit button is also on form but outside gridview. If any of the rows of gridview dropdownlist contain value as "Select" and click Submit button ,give message as "Please select value". I want to do this stuff using javascript. Thanks in advance.

pass number of rows of Gridview to a javascript function

using vb.net/asp.net 2005.I need to pass the number of rows of the Gridview to a javascript function does anyone know how to do this?  thanks

Gridview attribute changed by javascript is lost on postback

I have a gridview control that extends the default gridview.  I have added an attribute called "hiddenSelectedValues" to to the gridview during the "PreRender" event and I have a private variable that points to the value of that attribute. I have some javascript code that modifies the value of this attribute based on the user checking or unchecking checkboxes in the grid.  I have confirmed that the javascript is indeed modifying the value of the "hiddenSelectedValues" attribute by using Firebug to see the change as it happens. However, once a postback occurs, the grid looses the updated value of this attribute and I am unable to reference get the updated value on the server side. How do I keep the value of an attribute changed by javascript on postback?

Updating gridview attributes from javascript

Hello,   I have been trying to use a custom attribute in my gridview to pass a comma delimited list of guids between my server-side and client side code.  Normally I would just use a hidden-field to do this, but I have to add a hidden-field into a row in my gridview to use one.  Since I need access to the updated value from javascript before my grid is rendered on postback, I can't use a control that is buried inside a row.  So instead, i was trying to add an attribute to the gridview and having the javascript update that value.   Here is the private property defined in my extended gridview class:  private List<Guid> _selectedValues { get { List<Guid> myList = new List<Guid>(); if (this.SelectionType != SOMgridviewSelectionType.None) { if (ViewState["SelectedValues"] != null) { return (List<Guid>)ViewState["SelectedValues"]; } } return myList; } set { if (this.SelectionType != SOMgridviewSelectionType.None) { if (string.IsNullOrEmpty(this.Attributes["hiddenSelectedValues&q

Javascript code to copy specific cell of gridview row

Dears, I need a javascript code to copy the text content of a cell of a row in gridview. I have a button in each row that users click it and the text content a cell of that row should be copied in a textbox out of gridview

hide gridview column using javascript. working in ie and firefox but In firefox, gridview data is sh


function EnableDisableGridViewColumn() {
               var AdvanceSearch = document.getElementById('<%= chkboxlist1.ClientID %>');
               var chkList = AdvanceSearch.getElementsByTagName("input");
               var dgTest = document.getElementById("gridview1")
               if (dgTest != null)
                   for (var i = 1; i < dgTest.rows.length; i++) {

                       if (chkList[0].checked == true && chkList[1].checked == true) {
                           dgTest.rows[0].cells[0].style.display = "block";

Help:JAVASCRIPT (checkAll) & (Hide/Unhide GridView1) in a Datalist with a nested Gridview


Hey guys,

 I'm at my wits end on this one looked/Searched/Played/Experimented and I need your help if you can.

This page is going to be primarily used on a mobile device using Win Mobile 5


Need to Accomplish:

  1. Prevent Postback(serverside) of Page using JavaScript (Postback's slow down the page on mobile device)


JavaScript Requests:

  1. Hide and UnHide the Nested Gridview1 by Clicking on a imagebutton1 in DataList1icon_minized_collapse.pngicon_expand_collapse.png
  2. CheckBox in DataList1 Checks All and UNChecks All, CheckBox in just the related Gridview1


Controls :

  1. Gridview1 nested inside DataList1


Note: Datalist1 and Gridview1 have datasource's in production. The Codebehind page is just appling test data to help me figure this out.


Thank you all in advance for helping me with this.

Example data below:<

run javascript after gridview rowcommand has been executed


I want to run some javascript after a rowcommand has been executed.

I tried this, but its not working

Protected Sub gvSearchResults_OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvSearchResults.RowCommand
    Dim sb As New StringBuilder
    sb.Append("document.getElementById('" + Me.Master.CompareURL.ClientID.ToString + "').value='LALALAL';")
    Me.Page.ClientScript.RegisterStartupScript(Me.[GetType](), "test", sb.ToString(), True)
End Sub

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend