Show/Hide Single Row in ASP.NET Repeater

DogEars

I'm having trouble showing just a single row inside a repeater. I have all of them expanding correctly, but my efforts to show just that row have not worked out well.

 <asp:Repeater ID="rptPlayers" runat="server" OnItemDataBound="DataBound_ItemDataBoundEvent">
            <HeaderTemplate>
                <thead>
                    <tr>

                        <th>Name</th>

                        <th>Profile Approved?</th>
                        <th>Playing in <%: DateTime.Now.Year %>?</th>
                        <th>Roommate</th>
                        <th>Manage</th>
                    </tr>
                </thead>
            </HeaderTemplate>
            <ItemTemplate>
                <tbody>
                    <tr>
                        <td><a href="#" class="show_hide"><%# Eval("FirstName") %>&nbsp;<%# Eval("LastName") %></a></td>
                        <td style="display: none"><%# Eval("PlayerEmail") %></td>
                        <td>
                            <asp:CheckBox ID="chkApproved" runat="server" Checked='<%# Eval("ProfileApproved") %>' /></td>
                        <td>

                            <asp:CheckBox ID="chkPlayingCurrentYear" runat="server" Checked='<%# Eval("PlayingCurrentYear") %>' /></td>
                        <td>

                            <asp:DropDownList ID="ddlRoommate" runat="server" AppendDataBoundItems="True"></asp:DropDownList>&nbsp;
                            <asp:LinkButton ID="lnkAssign" runat="server" OnClick="AssignPlayer"></asp:LinkButton></td>
                        <td>
                            <asp:PlaceHolder ID="AdminActions" runat="server"></asp:PlaceHolder>
                            <p class="text-danger">
                                <asp:LinkButton ID="lnkApproveProfile" runat="server" OnClick="ApprovePlayer"></asp:LinkButton>
                                <asp:LinkButton ID="lnkConfirm" runat="server" OnClick="ConfirmPlayer"></asp:LinkButton>
                            </p>
                        </td>
                        <td style="display: none">
                            <asp:Literal ID="ltUserId" runat="server" Text='<%# Eval("PlayerId") %>'></asp:Literal></td>
                    </tr>
                    <tr>
                        <td colspan="6">
                            <div class="slidingDiv">
                                Fill this space with really interesting content. <a href="#" class="show_hide">hide</a>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </ItemTemplate>
        </asp:Repeater>

This is my current jQuery, what am I missing to just toggle a single row?

 <script type="text/javascript">
    $(document).ready(function () {
        $("div.slidingDiv").hide();
         $(".show_hide").show();
        $('.show_hide').click(function () {
            $(".slidingDiv").slideToggle();
           // $(this).next('div.slidingDiv').eq(0).slideToggle(800);


        });
    });
</script>
Mackan

If I need to take a best guess at what you want to do:

To make the jQuery toggle only the slidingDiv next to the row getting clicked:

$(document).ready(function () {
    $('.slidingDiv').hide();
    $('.show_hide').show();
    $('.show_hide').click(function () {
        var x = $(this).closest('tr').next();
        x.find('.slidingDiv').slideToggle();
    });
});

This will not work for the link "hide" inside the content row. I suggest you use another class for that, lets call it hideThis, and do another script for that:

$('.hideThis').click(function () {
    $(this).closest('div').slideToggle();
});   

Examples below:

$('.slidingDiv').hide();
$('.show_hide').show();
$('.show_hide').click(function () {
    var x = $(this).closest('tr').next();
    x.find('.slidingDiv').slideToggle();
});

$('.hideThis').click(function () {
    $(this).closest('div').slideToggle();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
    <tr>
        <td><a href="#" class="show_hide">show hide</a>

        </td>
        <td style="display: none">dfhdhdh</td>
        <td>fgjfgj</td>
        <td>fgjhfj</td>
        <td>fgjfjfj</td>
        <td>fgjfjfjgfjfj</td>
        <td style="display: none">fgjfjgjfgjfjgf</td>
    </tr>
    <tr>
        <td colspan="6">
            <div class="slidingDiv">Fill this space with really interesting content. <a href="#" class="hideThis">hide</a>

            </div>
        </td>
    </tr>
    <tr>
        <td><a href="#" class="show_hide">show hide</a>

        </td>
        <td style="display: none">dfhdhdh</td>
        <td>fgjfgj</td>
        <td>fgjhfj</td>
        <td>fgjfjfj</td>
        <td>fgjfjfjgfjfj</td>
        <td style="display: none">fgjfjgjfgjfjgf</td>
    </tr>
    <tr>
        <td colspan="6">
            <div class="slidingDiv">Fill this space with really interesting content. <a href="#" class="hideThis">hide</a>

            </div>
        </td>
    </tr>
</table>

Might I also suggest that you move the .slidingDiv class to the tr instead of the div. As it is right now you're only hiding the div, but the row is still there (even if most browsers would show it with minimal height).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

asp.net repeater for each row

From Dev

Fix header row in repeater in ASP.NET

From Dev

Fix header row in repeater in ASP.NET

From Dev

ASP.NET Repeater Item add divider after each row

From Dev

ASP.NET C# Continue row count in Gridview in Repeater

From Dev

NavigateUrl on Repeater ASP.net

From Dev

NavigateUrl on Repeater ASP.net

From Dev

Is there an ASP.NET databindable control (like Repeater), which only expects a single item?

From Dev

How can I bind the single LINQ object to ASP.NET Repeater Control

From Dev

Is there an ASP.NET databindable control (like Repeater), which only expects a single item?

From Dev

Perform count based on value of repeater control for each row C# ASP.NET

From Dev

ASP.NET Repeater - Eval() for bool?

From Dev

Convert Bootstrap Carousel to ASP.Net Repeater

From Dev

ASP .NET Using a Repeater inside of UpdatePanel with UpdateProgress

From Dev

repeater item command in asp.net

From Dev

to disable a label of repeater on some condition in asp .net

From Dev

Using Bootstrap tabs with ASP NET repeater

From Dev

asp.net repeater use template in javascript

From Dev

To bind images in repeater using asp.net

From Dev

asp.net repeater merge columns dynamically

From Dev

ASP.NET Converting repeater item to the textbox

From Dev

Repeater asp.net tag not working

From Dev

asp.net repeater merge columns dynamically

From Dev

Convert Bootstrap Carousel to ASP.Net Repeater

From Dev

Conditional statement for Repeater Controll in ASP.NET

From Dev

trying Image Button in repeater Asp.net

From Dev

asp net dropdown selectedvalue/selectedindex not updating in repeater

From Dev

ASP.Net - Issues with Repeater / DataBinding

From Dev

Repeater in asp.net from DB with DropDownList

Related Related

  1. 1

    asp.net repeater for each row

  2. 2

    Fix header row in repeater in ASP.NET

  3. 3

    Fix header row in repeater in ASP.NET

  4. 4

    ASP.NET Repeater Item add divider after each row

  5. 5

    ASP.NET C# Continue row count in Gridview in Repeater

  6. 6

    NavigateUrl on Repeater ASP.net

  7. 7

    NavigateUrl on Repeater ASP.net

  8. 8

    Is there an ASP.NET databindable control (like Repeater), which only expects a single item?

  9. 9

    How can I bind the single LINQ object to ASP.NET Repeater Control

  10. 10

    Is there an ASP.NET databindable control (like Repeater), which only expects a single item?

  11. 11

    Perform count based on value of repeater control for each row C# ASP.NET

  12. 12

    ASP.NET Repeater - Eval() for bool?

  13. 13

    Convert Bootstrap Carousel to ASP.Net Repeater

  14. 14

    ASP .NET Using a Repeater inside of UpdatePanel with UpdateProgress

  15. 15

    repeater item command in asp.net

  16. 16

    to disable a label of repeater on some condition in asp .net

  17. 17

    Using Bootstrap tabs with ASP NET repeater

  18. 18

    asp.net repeater use template in javascript

  19. 19

    To bind images in repeater using asp.net

  20. 20

    asp.net repeater merge columns dynamically

  21. 21

    ASP.NET Converting repeater item to the textbox

  22. 22

    Repeater asp.net tag not working

  23. 23

    asp.net repeater merge columns dynamically

  24. 24

    Convert Bootstrap Carousel to ASP.Net Repeater

  25. 25

    Conditional statement for Repeater Controll in ASP.NET

  26. 26

    trying Image Button in repeater Asp.net

  27. 27

    asp net dropdown selectedvalue/selectedindex not updating in repeater

  28. 28

    ASP.Net - Issues with Repeater / DataBinding

  29. 29

    Repeater in asp.net from DB with DropDownList

HotTag

Archive