Click here to Skip to main content
16,001,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
function SelectAccess(CheckBox) {

       var chkAc1 = document.getElementById('ctl00_MainContent_CheckBoxAccess').checked;
            if (document.getElementById('ctl00_MainContent_CheckBoxAccess').checked) {

                var ParentGrid = document.getElementById("<%= gvParentGrid.ClientID %>");

                if (ParentGrid.rows.length > 0) {
                    alert(ParentGrid.rows.length);
                    var chidgrid = $('#<%= gvParentGrid.ClientID %> table');

                    var chidgridVal = document.getElementById('ctl00_MainContent_gvParentGrid_ctl02_gvChildGrid');

                    if (chidgridVal.rows.length > 0) {
                        alert(chidgridVal.rows.length);


                        for (var j = 1; j < 11; j++) {

                            for (var i = 1; i <= chidgridVal.rows.length; i++) {

                               document.getElementById('ctl00_MainContent_gvParentGrid_ctl0' + (j + 1).toString() + '_gvChildGrid_ctl0' + (i + 1).toString() + '_ui_access').checked = true;

                               document.getElementById('ctl00_MainContent_gvParentGrid_ctl0' + (j + 2).toString() + '_gvChildGrid_ctl0' + (i + 1).toString() + '_ui_access').checked = true;
                            }
                       }
                    }
                 }
       }

   }

The above code for javascript but when the inside for loop gets executed the outer for do not get executed and j do not get incremented so for loop do not get executed completely.How to resolve this?My outer for loop executes at 1st time then inner for loop get executed till the lenght of rows, after execution of innner loop my j should get incremented and outer loop must get exceuted 1's again and then finally inner loop.
But my inner once executed do no go outside and exceution stops so only when value of j=1 the i increments and executed j 's value do not get incrmented.
Posted
Updated 5-Aug-13 19:03pm
v2

1 solution

Member 9410081570 wrote:
…when the inside for loop gets executed the outer for do not get executed…
Please forgive me this expression, but this is called gibberish: http://en.wikipedia.org/wiki/Gibberish[^]. I'll explain…

I hope you just messed up your wording, because the logic is way too simple. If inner loop is executing, how its outer loop could probably no executed? If it was the case, the execution would not even reach the inner loop. Your observations are simply incorrect: it's absolutely clear that your outer loop would execute 10 times, but only if there is no exception thrown in an inner loop. If exception is thrown, it will still execute once.

Now, about the exception: it's very strange that your loop starts from 1, not 0. All indexing of all collections is always zero-based. And you also increment the expression for id by 1 and 2. Are you sure that your IDs are numbered starting from 2? Perhaps you need to renumber your IDs in a regular zero-based manner, to avoid mess-up.

After all, you need to run your code under the debugger, to see what's really going on.

—SA
 
Share this answer
 
Comments
Member 9410081 6-Aug-13 1:02am    
My outer for loop executes at 1st time then inner for loop get executed till the lenght of rows, after execution of innner loop my j should get incremented and outer loop must get exceuted 1's again and then finally inner loop.
But my inner once executed do no go outside and exceution stops so only when value of j=1 the i increments and executed j 's value do not get incrmented.
Sergey Alexandrovich Kryukov 6-Aug-13 1:05am    
It cannot be so. It goes out, or, if exception is thrown, it propagates far out...
—SA
Member 9410081 6-Aug-13 1:10am    
Do u have any idea about any mistk in above for loop
Sergey Alexandrovich Kryukov 6-Aug-13 1:14am    
I already told you what I see. Rewrite the code in accurate civilized manner... And I don't see you HTML and your IDs...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900