Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends,

I have created grid header using div.
Here is code:
<div id="HeaderDiv" style="width: 833px; height: 35px; overflow: hidden; padding-removed 0px; border-bottom-width: 0px;">
        <table class="" cellspacing="0" cellpadding="" border="1px" style="border-style: none; border-collapse: collapse; width: 2015px;" rules="all">
            <tbody>
                <tr class="" style="font-weight: bold;">
                    <td style="width: 102px;">
                        <span id="cphPage_gvForecastSummary_lblCheckInclude" class="ms-label" style="color:White;">Include</span>
                        <br/>
                        <span class="ms-label" style="border-color:LightBlue;">
                            <input id="cphPage_gvForecastSummary_chkSelectAll" type="checkbox" onclick="selectAll(this);" name="ctl00$cphPage$gvForecastSummary$ctl01$chkSelectAll">
</span>
</td>
<td style="width: 95px;">Business Type</td>
<td style="width: 69px;">Type</td>
<td style="width: 80px;">Close Month</td>
</tr>
</tbody>
</table>
</div>


I was trying to disable checkbox in grid header using following javascript:
function chkbxDisable() {
            var objButton = document.getElementById("<%=btnSetDraft.ClientID %>");
            if (!objButton) {
                var tableGrid = document.getElementById("<%=gvForecastSummary.ClientID %>");
                var objchkbox = document.getElementById("HeaderDiv").getElementsByTagName("input");
                alert(objchkbox.length);
                for (var i = 0; i < objchkbox.length; i++) {
                    alert(objchkbox[i].type.toUpperCase());
                    if (objchkbox[i].type.toUpperCase() == "CHECKBOX") 
                    {
                        alert("In");
                        //objchkbox[i].disabled = true;
                        objchkbox[i].display = 'none';
                    }
                }
                for (var i = 1; i < tableGrid.rows.length; i++) {
                    tableGrid.rows[i].cells[0].childNodes[0].childNodes[0].disabled = true;
                }
            }
        }


Problem is that the input tag does not get detect, collection contains 0 element and first for loop does not execute.

Can any one tell me where I'm going wrong??

Thanks in advance
Posted
Comments
E.F. Nijboer 23-May-12 3:42am    
Are you sure you call chkbxDisable somewhere?
dhage.prashant01 23-May-12 4:44am    
Yes in codebehind
Function is getting called, only first loop is not executing.
dhage.prashant01 23-May-12 5:06am    
Actually the table inside the HeaderDiv is automatically generated using javascript.

try to use as Id "cphPage_gvForecastSummary_chkSelectAl" instead of
HTML
<%=gvForecastSummary.ClientID %>
in
C#
document.getElementById("<%=gvForecastSummary.ClientID %>")
 
Share this answer
 
v2
Comments
Jim Jos 23-May-12 4:13am    
You also need to get the button name right You have not put the code for button here.. please make sure button id is exactly mentioned in -- document.getElementById("<%=btnSetDraft.ClientID %>");
dhage.prashant01 23-May-12 4:49am    
Everything working fine, only
var objchkbox = document.getElementById("HeaderDiv").getElementsByTagName("input");
does not detect checkbox
in java script do like this it will sure work.
JavaScript
function chkbxDisable() {
               
               var objButton = document.getElementById("btnSetDraft");
            alert(objButton);
            if (objButton!=null) {

               
                var tableGrid = document.getElementById("gvForecastSummary");
                var objchkbox = document.getElementById("HeaderDiv").getElementsByTagName("input");
                alert(objchkbox.length);
                for (var i = 0; i < objchkbox.length; i++) {
                    
                    if (objchkbox[i].type.toUpperCase() == "CHECKBOX") 
                    {
                        alert(objchkbox[i].type.toUpperCase());
                        
                        alert("In");
                        objchkbox[i].style.display = 'none';
                    }
                }
                for (var i = 1; i < tableGrid.rows.length; i++) {
                    tableGrid.rows[i].cells[0].childNodes[0].childNodes[0].disabled = true;
                }
            }
        }
 
Share this answer
 
v2
Sorry friends
I was making call to that function before the header getting created

Now it is working fine =)
 
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