Click here to Skip to main content
16,004,647 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried below the table design, but I m not able to success.

plz help..thanks

What I have tried:

<p>
    <input type="checkbox" name="ProjectGroupName" checked="checked"> ProjectGroupName
    <input type="checkbox" name="ProjectName">ProjectName
    <input type="checkbox" name="BugID" checked="checked"> BugID
</p>

<table class="table table-striped table-bordered table-hover" cellspacing="0" rules="all" border="1" id="ctl00_ContentPlaceHolder1_GridViewUserControlnew_grdUserControl" style="border-collapse:collapse;">
    <tr>
        <th name="ProjectGroupName" scope="col"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridViewUserControlnew$grdUserControl','Sort$ProjectGroupName')">ProjectGroupName</a></th>
        <th name="ProjectName" scope="col"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridViewUserControlnew$grdUserControl','Sort$ProjectName')">ProjectName</a></th>
        <th name="BugID" scope="col"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridViewUserControlnew$grdUserControl','Sort$BugID')">BugID</a></th>
    </tr>
    <tr> 
        <td name="ProjectGroupName">Test Group</td>
        <td name="ProjectName">7.3</td>
        <td name="BugID">36244</td>
    </tr>
    <tr>
        <td name="ProjectGroupName">Test Group 2</td>
        <td name="ProjectName">Interface 1.1</td>
        <td name="BugID">3212</td>
    </tr>
    <tr>
        <td name="ProjectGroupName">Team Management</td>
        <td name="ProjectName">RR CE</td>
        <td name="BugID">3232</td>
    </tr>
    <tr>
        <td name="ProjectGroupName">Test Group 3</td>
        <td name="ProjectName">Testing Project</td>
        <td name="BugID">1</td>
    </tr>
</table>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
    $("input:checkbox:not(:checked)").each(function () {
        var column = "table ." + $(this).attr("name");
        $(column).hide();
    });

    $("input:checkbox").click(function () {
        var column = "table ." + $(this).attr("name");
        $(column).toggle();
    });
</script>
Posted
Updated 22-Feb-18 20:19pm
Comments
ZurdoDev 19-Feb-18 9:36am    
What is the problem?
venkatesh (chennai) 20-Feb-18 7:50am    
I m trying to show/hide columns while check the Checkbox...
but i m unable to done this...this is my problem..

1 solution

Hi,

line "$(column).hide();" == "$(table .ProjectGroupName).hide()"; which means under table all class name start with ProjectGroupName should go hide or show.
but in the html you have used "name" attribute instead of class attribute.that's why it is not working.

below is the full code solution:

Script Part:


$(document).ready(function() {
$("input[type=checkbox]").on('change', function() {
var column = "table ." + $(this).attr("name");
alert(column);
$(column).toggle();
});
});

<p>
       <input type="checkbox" name="ProjectGroupName" checked="checked" />
       ProjectGroupName
       <input type="checkbox" name="ProjectName" />
       ProjectName
       <input type="checkbox" name="BugID" checked="checked" />
       BugID
   </p>
   <table class="table table-striped table-bordered table-hover" cellspacing="0" rules="all"
       border="1" id="ctl00_ContentPlaceHolder1_GridViewUserControlnew_grdUserControl"
       style="border-collapse: collapse;">
       <tr>
           <th class="ProjectGroupName" scope="col">
               <a>ProjectGroupName</a>
           </th>
           <th class="ProjectName" scope="col" >
               <a>ProjectName</a>
           </th>
           <th class="BugID" scope="col" >
               <a>BugID</a>
           </th>
       </tr>
       <tr>
           <td class="ProjectGroupName">
               Test Group
           </td>
           <td class="ProjectName">
               7.3
           </td>
           <td class="BugID">
               36244
           </td>
       </tr>
       <tr>
           <td class="ProjectGroupName">
               Test Group 2
           </td>
           <td class="ProjectName">
               Interface 1.1
           </td>
           <td class="BugID">
               3212
           </td>
       </tr>
       <tr>
           <td class="ProjectGroupName">
               Team Management
           </td>
           <td class="ProjectName">
               RR CE
           </td>
           <td class="BugID">
               3232
           </td>
       </tr>
       <tr>
           <td class="ProjectGroupName">
               Test Group 3
           </td>
           <td class="ProjectName">
               Testing Project
           </td>
           <td class="BugID">
               1
           </td>
       </tr>
   </table>


Please vote!!!

Regards,
Sarita Singh
 
Share this answer
 
v2
Comments
venkatesh (chennai) 5-Mar-18 7:39am    
thanks its working

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