回传时扩展的嵌套中继器崩溃

时间:2018-10-04 18:13:20

标签: asp.net .net-4.5 repeater collapsable

我有一个嵌套的中继器,内部的中继器可以通过单击外部中继器中的链接来扩展/折叠。我不确定如何设置展开/折叠部分并this post解决了这个问题。

但是,现在,如果我单击内部转发器中的链接,则在展开后,由于回发,它会折叠。我试图使用隐藏的输入来存储表示转发器项目状态的值,并使用它来扩展/折叠,但是它不起作用。

<asp:Repeater runat="server" ID="rptCategoryList" OnItemDataBound="rptCategoryList_ItemDataBound">
    <ItemTemplate>
        <div style="font-size: 120%">
            <%# Eval("CourseCategory")%>
            <i class="br-plus" class="fa fa-plus-circle" style="color: #3697EA; margin-left: 1%; margin-top: 60px;" data-cat="<%# Eval("Abbrev")%>"></i>
            <i class="br-minus" class="fa fa-minus-circle" style="color: #3697EA; margin-left: 1%; margin-top: 60px; display: none;" data-cat="<%# Eval("Abbrev")%>"></i>
        </div>
        <!-- This is the expanding/collapsing part -->
        <div class="row">
            <asp:Repeater runat="server" ID="rptCourses" OnItemDataBound="rptCourses_ItemDataBound" OnItemCommand="rptCourses_ItemCommand">
                <HeaderTemplate>
                    <div class='<%# DataBinder.Eval(Container.NamingContainer.NamingContainer, "DataItem.Abbrev")%>' style="display: none; margin-top: 10px; font-size: 26px; width: 90%;" >
                    <table>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr style="border-top: 1px solid #000;">
                        <td style="padding-top: 30px;">
                        </td>
                        ...
                        <td style="padding-top: 30px;">
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                    </div>
                </FooterTemplate>
            </asp:Repeater>            
        </div>
    </ItemTemplate>
</asp:Repeater>

<script type="text/javascript">

    $(function () {
        $('.br-plus').on('click', function () {
            //expand($(this)); 
            $('#hfOpenPanel').val('true');
            var cat = $(this).data("cat")
            $('.' + cat).toggle();
            $(this).hide();
            $(this).siblings().show();
        });

        $('.br-minus').on('click', function () {
            //collapse($(this));
            $('#hfOpenPanel').val('false');
            var cat = $(this).data("cat")
            $('.' + cat).toggle();
            $(this).hide();
            $(this).siblings().show();
        });
    });

    function expand(that) {debugger
        $('#hfOpenPanel').val('1');
        var cat = that.data("cat")
        $('.' + cat).toggle();
        that.hide();
        that.siblings().show();
    }
    function collapse(that) {debugger
        $('#hfOpenPanel').val('0');
        var cat = that.data("cat")
        $('.' + cat).toggle();
        that.hide();
        that.siblings().show();
    }

    function checkState() {debugger
        if ($('#hfOpenPanel').val() == 1)
            expand($('.br-plus'));
        else
            collapse($('.br-minus'));
    }
</script>

在后面的代码中:试图调用checkState(),没有运气

protected void rptCourses_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    // do whatever that causes postback

    Page.ClientScript.RegisterStartupScript(this.GetType(), "keepOpen", "checkState();", true);

    }

0 个答案:

没有答案
相关问题