Click here to Skip to main content
15,798,200 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';

                        <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">
                             <asp:BoundField  HeaderText = "CourseCatID" DataField="CourseCatID" />
                             <asp:TemplateField HeaderText="Course Category">
                                       <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">

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

1 solution


Please modify your code as per following:

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

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

Share this answer
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 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