Play turn gridview GridView corresponding row value auto-summary

Source: Internet
Author: User

Preface:

The demand for this piece has been mentioned in the previous blog ("Play the GridView" to let the GridView Move (a)), which is a summation between the Chinese text box embedded in the GridView. Before the practice is all written in the background code, and later test bug-"embedded Copy button need to double-click to take effect", has not understood how caused, and later through the big God guidance, debugging found is two backstage method in the back of the conflict, only to appear such problems.

Since the development of new features, this bug left about two weeks, the recent development of new features, and colleagues consulted a bit, the real-time changes in all the things in the JS.

Questions:

As adjustments and quotas change, the total will change in real time.

The first problem is how to get the value embedded in the GridView text box in JS. How to add and assign data for a row, and also guarantee the same row.

Ideas:

First get the rowindex of the row, according to the parameters can get the value of the current text box, and then if you modify the adjustment amount, you need to obtain a fixed value, and then the sum of the two, assign to the corresponding adjustment total. Gets the ID value of the GridView before

          getElementsByTagName ("input") [Index].value
Gets the value. The assignment is reversed in the same way as to be OK.

Just take a look at the code and you'll see.

Code:

        When the adjustment amount changes, the total amount changes in real time function Count (result) {//Get line number var index = Result.parentNode.par

            Entnode.rowindex;
             
            Gets the modified integer value var adjvalue = Result.value;
            Determines if the text box is empty, the direct return does not evaluate if (IsNaN (adjvalue) = = True | | adjvalue = = ") {return; }//Get the fixed value if (index = = 1) {var adjust = document.getElementById (' <%= grvdetail .
            ClientID%> '). getElementsByTagName ("input") [0].value; } else {var adjust = document.getElementById (' <%= grvdetail.clientid%> '). getElementsByTagName ("InP
            UT ") [7 * (index-1)].value;

            } var adjallcost = parsefloat (adjvalue) + parsefloat (adjust); if (index = = 1) {document.getElementById (' <%= grvdetail.clientid%> '). getElementsByTagName ("input")
            [index + 2].value = adjallcost; } else {Document.getelementbyId (' <%= grvdetail.clientid%> '). getElementsByTagName ("input") [Index + (6 * index-4)].value = Adjallcost; }
        }

Effect Diagram:

When using the Copy button, the automatic summary data is implemented in the background method (PS: See blog "Play to the GridView" Let the GridView Move (a) "); When the adjustment amount changes, the total amount changes.

Summary:

When we change the bug, it is the same as the function of the re-thinking and understanding. To see if there is a problem with the business logic, or the code is not strict enough to write. In any case, changing a bug is also a learning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.