Click here to Skip to main content
16,016,669 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all
what is wrong in this javascript code:

<script type="text/javascript">
    function CountRows() {
        var totalRowCount = 0;
        var rowCount = 0;
        var gridView = document.getElementById("<%=GridView1.ClientID %>");
        var rows = gridView.getElementsByTagName("tr")
        for (var i = 0; i < rows.length; i++) {
            totalRowCount++;
            if (rows[i].getElementsByTagName("td").length > 0) {
                rowCount++;
            }
        }
        document.getElementById("lbl_total_users").innerText = totalRowCount;
        return false;
    }
</script>


I want to display value of totalRowCount on my label

What I have tried:

how to display value on label using javascript in asp.net
Posted
Updated 5-May-16 21:17pm
Comments
Kornfeld Eliyahu Peter 1-May-16 13:06pm    
You should tell us what's wrong...After all you are the only one who knows what is good...After that someone may tell you the 'why'...
rezaeti 1-May-16 14:07pm    
the problem is that value does not show on label
Karthik_Mahalingam 7-May-16 8:17am    
always use Reply button to Reply/Comment/Ask, so that the user will get notified.
did you try solution1 ?
F-ES Sitecore 1-May-16 14:55pm    
You code works fine for me so it must be something to with your markup, or how you're calling the function or something else you just haven't told us. Check the console for errors and use the "debugger;" keyword to step through your code in the browser tools to try and see what is going on.
Sergey Alexandrovich Kryukov 1-May-16 15:01pm    
Why label? A label is supposed to be used to label some other HTML element, a control; and it should add an access key to focus it. It is rarely needs to be modified.
—SA

1 solution

Try using innerHTML[^]
JavaScript
document.getElementById("<%=lbl_total_users.ClientID%>").innerHTML = totalRowCount;
 
Share this answer
 

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