Click here to Skip to main content
15,890,422 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Here is my code:
<script type="javascript">
    function toggleDiv(mydiv) {
        if (document.getElementById(divid).style.display == 'none') {
            document.getElementById(divid).style.display = 'block';
        } else {
            document.getElementById(divid).style.display = 'none';
        }
    }
</script>






                        <asp:GridView ID="grdCategory" runat="server" AutoGenerateColumns="False"   
                            Width="813px" DataKeyNames="CourseCatID" Font-Names="verdana,arial,helvetica,sans-serif" Font-Size="8pt" CellPadding="4" ForeColor="#333333" GridLines="None">
                            <columns>
                             <asp:BoundField  HeaderText = "CourseCatID" DataField="CourseCatID" />
                             
                             <asp:TemplateField HeaderText="Course Category">
                                 <itemtemplate>
                                       <asp:Label ID="lbllastname" Height="15px" runat="server" Text='<%# Eval("CourseCatName")%>'> 
                                       <a href="java<!-- no -->script:;" önclick="if(document.getElementById('mydiv').style.display == 'none'){ document.getElementById('mydiv').style.display = 'block'; }else{ document.getElementById('mydiv').style.display = 'none'; }">[+]</a> 
                                       <div id="mydiv" style="display:none">
</div>
</itemtemplate></columns>

Please sir help me cause when I click on the fisr row it show the inner grid of the first row but when I click on the second row it shows the inner grid of the first row again. Sir youlld you spare your time with me so the i could debug this code.? thanks and more power
Posted

1 solution

Hi,

Please modify your code as per following:

XML
<a href="javascript:toggleDiv('mydiv' + <%# Eval(" coursecatid=")%>)">[+]</a>
<div id="mydiv<%# Eval("CourseCatID")%>" style="display:none">
</div>


Note: this would only work if CourseCatID has Unique value.


Thanks,
Imndadhusen
 
Share this answer
 
Comments
janwel 21-Nov-11 0:16am    
Sir your code is not working properly... Sir I dont mean to offend but sir now the div is not showing even if I click the first row.. Please help
janwel 21-Nov-11 0:41am    
Sir using http://weblogs.asp.net/pleloup/archive/2006/04/26/444055.aspx ive manage to set a breakpoint and im getting an error it says Microsoft JScript runtime error: Object expected and the id is ToggleDiv('mydiv20') so sir your right cause when I choose another one it say ToggleDive('mydiv44') but it is not using my javascript. Please sir help me
Sunasara Imdadhusen 21-Nov-11 3:38am    
Please provide snippet of code!

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