无法在页面回发时保持转发器内部面板的展开或折叠状态

时间:2019-05-20 09:39:39

标签: javascript html asp.net panel postback

我在asp:Repeater中使用asp:Panel显示多个表。现在,默认情况下,所有表都处于折叠状态。有一个名为“折叠卡”的类。现在的问题是,当用户展开它并单击一个按钮导致回发时,面板将不会停留在展开状态。因为有多个表,所以我不知道它是如何完成的。

我尝试使用hiddenfield,但是一次只存储一个值。

我尝试过的Javascript

<script type="text/javascript">
        function setPanelState() {
            var x = document.getElementsByClassName("PanelStatusHF");
            x.value = "1";
        }
    </script>

下面是我的aspx标记:

<div class="card-body">
                            <div class="row">
                                <asp:Repeater ID="rptrTables" runat="server" OnItemDataBound="rptrTables_ItemDataBound">
    <ItemTemplate>
        <div class="col-md-6">
            <asp:Panel ID="dvTable" runat="server" CssClass="card card-info collapsed-card" ClientIDMode="Static">
                <div class="card-header with-border">
                    <h3 class="card-title">
                        <asp:Label ID="lblTableNumber" runat="server" Text='<%# Eval("TableName") %>'></asp:Label></h3>
                    <asp:HiddenField ID="TableStatusHF" runat="server" Value='<%# Eval("TableStatus") %>' />
                    <asp:HiddenField ID="PanelStatusHF" runat="server" Value="0" CssClass="PanelStatusHF" />
                    <div class="card-tools">
                        <button type="button" class="btn btn-tool" data-widget="collapse">
                            <i class="fa fa-minus"></i>
                        </button>
                    </div>
                </div>
                <div class="card-body" style="height:350px; overflow:scroll">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <asp:GridView ID="grdOrder" runat="server" AutoGenerateColumns="false" AllowPaging="true"
                                    CssClass="table table-bordered table-hover table-responsive" GridLines="None"
                                    PageSize="10" ShowFooter="true" OnRowDataBound="gvRowDataBound">
                                    <Columns>
                                        <asp:CommandField ShowDeleteButton="true" ControlStyle-CssClass="btn btn-danger fa fa-trash"
                                            DeleteText="" HeaderText="Remove" />
                                        <asp:TemplateField HeaderText="Items" ItemStyle-Wrap="false" HeaderStyle-Wrap="false">
                                            <ItemTemplate>
                                                <asp:DropDownList ID="drpItemname" runat="server" Width="165px" CssClass="form-control select2" OnSelectedIndexChanged="GetItemDetails" AutoPostBack="true">
                                                </asp:DropDownList>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Price">
                                            <ItemTemplate>
                                                <asp:TextBox ID="lblUnitPrice" runat="server" CssClass="form-control" Text='<%# Eval("Column2")%>'></asp:TextBox>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Qty">
                                            <ItemTemplate>
                                                <asp:TextBox ID="lblQuantity" runat="server" CssClass="form-control" Text='<%# Eval("Column3")%>' OnTextChanged="CalculateLineTotal" AutoPostBack="true" TextMode="Number"></asp:TextBox>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Line Total">
                                            <ItemTemplate>
                                                <asp:TextBox ID="lblLineTotal" runat="server" CssClass="form-control" Text='<%# Eval("Column4")%>'></asp:TextBox>
                                            </ItemTemplate>
                                            <FooterStyle HorizontalAlign="Right" />
                                            <FooterTemplate>
                                                <asp:Button ID="ButtonAdd" runat="server" CssClass="btn btn-primary" Text="Add" OnClick="AddItem" />
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </div>
                        </div>
                        <div class="col-md-3">
                             <div class="form-group">
                                 <label>Sub Total</label>
                                 <asp:TextBox ID="txtSubTotal" runat="server" CssClass="form-control" placeholder="Sub Total" Enabled="false" Text="0"></asp:TextBox>
                             </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group">
                                <label>Enter GST %</label>
                                <asp:TextBox ID="txtGst" runat="server" CssClass="form-control" placeholder="GST %" TextMode="Number" Text="0"></asp:TextBox>
                            </div>
                        </div>
                        <div class="col-md-3">
                             <div class="form-group">
                                 <label>Grand Total</label>
                                 <asp:TextBox ID="txtGrandTotal" runat="server" CssClass="form-control" placeholder="Grand Total" Enabled="false" Text="0"></asp:TextBox>
                             </div>
                        </div>
                        <div class="col-md-6">
                             <div class="form-group">
                                 <label>Customer Name</label>
                                 <asp:TextBox ID="txtCustomerName" runat="server" CssClass="form-control" placeholder="Customer Name"></asp:TextBox>
                             </div>
                        </div>
                        <div class="col-md-6">
                             <div class="form-group">
                                 <label>Customer Mobile</label>
                                 <asp:TextBox ID="txtCustomerMobile" runat="server" CssClass="form-control" placeholder="Mobile Number"></asp:TextBox>
                             </div>
                        </div>                        
                    </div>
                </div>
                <div class="card-footer">
                    <div class="pull-right">
                        <asp:Button ID="btnSubmit" runat="server" CausesValidation="false" TabIndex="2" CssClass="btn btn-primary"
                            Text="Print KOT" />
                        <asp:Button ID="Button1" runat="server" CausesValidation="false" TabIndex="2" CssClass="btn btn-primary"
                            Text="Print Final Bill" />
                        <asp:Button ID="Button2" runat="server" CausesValidation="false" TabIndex="2" CssClass="btn btn-primary"
                            Text="Complete Order" />
                    </div>
                </div>
            </asp:Panel>
            <%--<div id="dvTable" runat="server" class="card card-info  collapsed-card">--%>

            <%--</div>--%>
        </div>
    </ItemTemplate>
</asp:Repeater>
<br />
<%--<asp:Button Text="Save" runat="server" OnClick="Save" />--%>
                            </div>
                        </div>

以下是我的C#代码:

protected void rptrTables_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            foreach (RepeaterItem RepeaterItems in rptrTables.Items)
            {
                Panel divTable = (Panel)e.Item.FindControl("dvTable");
                HiddenField TableStatus = (HiddenField)e.Item.FindControl("TableStatusHF");
                HiddenField PanelStatus = (HiddenField)e.Item.FindControl("PanelStatusHF");

                if (PanelStatus.Value == "0")
                {
                    if (TableStatus.Value == "1")
                    {
                        divTable.CssClass = divTable.CssClass.Replace("card card-primary collapsed-card", "card card-danger");
                    }
                    else if (TableStatus.Value == "0")
                    {
                        divTable.CssClass = divTable.CssClass.Replace("card card-danger collapsed-card", "card card-primary");
                    }
                }
                else if (PanelStatus.Value == "1")
                {
                    if (TableStatus.Value == "1")
                    {
                        divTable.CssClass = divTable.CssClass.Replace("card card-primary collapsed-card", "card card-danger collapsed-card");
                    }
                    else if (TableStatus.Value == "0")
                    {
                        divTable.CssClass = divTable.CssClass.Replace("card card-danger collapsed-card", "card card-primary  collapsed-card");
                    }
                }
            }
        }
    }

我正在发布以下问题的屏幕截图: Screenshot

0 个答案:

没有答案