在Gridview中显示Gridview

问题描述 投票:0回答:1

我有一个2列的网格视图([+]和[数据])。点击[+]符号,它会在同一个gridview中打开一个girdview。

现在,在子gridview我有一个链接按钮,点击它我显示一些数据。在回发时,gridview保留其原始位置,我想要显示子gridview。

码。

<asp:GridView ID="grvNeverTouchedQuartile" class="form-table" Width="100%" OnRowCommand="grvNeverTouchedQuartile_RowCommand"
                                                                AutoGenerateColumns="false" runat="server" OnRowDataBound="grvNeverTouchedQuartile_RowDataBound"
                                                                DataKeyNames="QuartileType">
                                                                <Columns>
                                                                    <asp:TemplateField>
                                                                        <ItemTemplate>
                                                                            <%--<asp:LinkButton ID="lnkbtnNTQuartile" runat="server" Text='<%# Eval("Quartile") %>'
                                                                        CommandArgument='<%# Eval("QuartileType") %>' CommandName="NeverTouched"></asp:LinkButton>--%>
                                                                            <img alt="Image not available" style="cursor: pointer" src="../images/plus.png" />
                                                                            <asp:Panel ID="pnl_NTChildGrid" runat="server" Style="display: none">
                                                                                <table>
                                                                                    <tr>
                                                                                        <td>
                                                                                            <div style="overflow: auto;">
                                                                                                <asp:GridView ID="grdNTInsuranceData" runat="server" AutoGenerateColumns="false" OnRowCommand="grdNTInsuranceData_RowCommand">
                                                                                                    <Columns>
                                                                                                        <asp:TemplateField HeaderText="Insurance Name">
                                                                                                            <ItemTemplate>
                                                                                                                <asp:Label ID="lblNTQuartileType" runat="server" Text='<%# Eval("QuartileType") %>' Visible="false"></asp:Label>
                                                                                                                <asp:Label ID="lblNTInsuranceName" runat="server" Text='<%# Eval("InsuranceName") %>' Visible="false"></asp:Label>
                                                                                                                <asp:LinkButton ID="lnkbtnNTInsuranceQuartile" runat="server" Text='<%# Eval("InsuranceNameDetails") %>'
                                                                                                                    CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="NeverTouchedInsurance"></asp:LinkButton>
                                                                                                            </ItemTemplate>
                                                                                                        </asp:TemplateField>
                                                                                                    </Columns>
                                                                                                </asp:GridView>
                                                                                            </div>
                                                                                        </td>
                                                                                    </tr>
                                                                                </table>
                                                                            </asp:Panel>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="Quartile[Count - $Value]">
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="lblNTQuartile" runat="server" Text='<%# Eval("Quartile") %>'></asp:Label>
                                                                            <%--<asp:LinkButton ID="lnkbtnNTQuartile" runat="server" Text='<%# Eval("Quartile") %>'
                                                                        CommandArgument='<%# Eval("QuartileType") %>' CommandName="NeverTouched"></asp:LinkButton>--%>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                </Columns>
                                                            </asp:GridView>

提前致谢!!!

c# jquery asp.net gridview
1个回答
0
投票

有一些方法(这不是代码,它只是我的建议,有代码通过互联网或它是基于经验)所以在我看来,你可以使用以下案例之一:

1-您应该使用UpdatePanel来防止刷新页面并将网格放在UpdatePanel中,仅用于下面的示例:

<asp:UpdatePanel ID="panelId" UpdateMode="Conditional" runat="server"  >
    <ContentTemplate>
     <asp:GridView ID="gvPrList" runat="server" AutoGenerateColumns="false" AllowPaging="false"
           AllowSorting="false" CssClass="list-table" HeaderStyle-CssClass="header">
           <Columns>
         <ItemTemplate>
                    <asp:LinkButton ID="lnkbtnNTInsuranceQuartile" runat="server" Text='<%# Eval("InsuranceNameDetails") %>'
                                                                                                                   CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' CommandName="NeverTouchedInsurance"></asp:LinkButton>
               </ItemTemplate>
           </asp:TemplateField>
       </Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

2- runatlnkbtnNTInsuranceQuartileserver,主要是在点击后回发后所以页面得到刷新为此你可以将你的lnkbtnNTInsuranceQuartile改为HTML元素,如<div><a class="x">click here</a><span class="detail"/></div>然后而不是lnkbtnNTInsuranceQuartile点击使用ajax然后更新细节Span something喜欢 :

    $('.x').click(function () {
    var $me = this;
    $.ajax({
        url: 'Your Web Method address',
        data: { youData},
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            //update span here
            $me.parent().find('.details.'.html(your response);
        },
        error: function (x, e) { 
        }
    });
});

3-使用客户端网格而不是ASP.Net GridView

4-将折叠的th的id添加到localstorage中并在页面加载后再次打开它...

5-等...

以上三个步骤都可以根据您的方案实施......

希望能帮到你

© www.soinside.com 2019 - 2024. All rights reserved.