简体   繁体   English

如何在模式弹出窗口中使用Gridview分页ASP.NET Bootstrap 4.0

[英]How to use Gridview Paging in modal popup window ASP.NET Bootstrap 4.0

Need Suggestions, why paging is not working correctly or event fire up but popup page are not refreshed correctly. 需要建议,为什么分页无法正常工作或事件启动但弹出页面未正确刷新。 I made a User Control with Bootstrap modal content and a GridView. 我制作了一个具有Bootstrap模式内容和GridView的用户控件。

ASP Page (Control): ASP页(控件):

<asp:Panel runat="server" ID="pModal">
<div class="modal fade" id="searchDiv" role="dialog" aria-labelledby="Adresse wählen:" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
            <ContentTemplate>
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <asp:GridView ID="gvSearch" runat="server" CssClass="table table-hover table-responsive-sm table-sm table-bordered" AllowPaging="True" AllowSorting="true"
                            PageSize="5" AutoGenerateColumns="true" ShowHeaderWhenEmpty="true"
                            OnPageIndexChanging="gvSearch_PageIndexChanging" PagerSettings-PageButtonCount="5">
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:Button ID="btnGvOK" runat="server" Text="OK" CssClass="btn btn-dark" OnClick="btnGvOK_Click" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <PagerSettings PageButtonCount="5" />
                            <PagerStyle CssClass="pagination" HorizontalAlign="Justify" />
                        </asp:GridView>
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</div>

With this script I show the popup: 使用此脚本,我显示弹出窗口:

public void LoadUC(DataTable dt)
{
    dtSource = dt;
    if (dtSource.Rows.Count > 0)
    {
        LoadSearchGridView();
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script",
            "<script> $('#searchDiv').modal('show'); </script>", false);
        upModal.Update();
    }
}

So I change the page: 因此,我更改页面:

protected void gvSearch_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gvSearch.PageIndex = e.NewPageIndex;
    LoadSearchGridView();
    upModal.Update();
}

When I am changing the page I obtain that: 当我更改页面时,我得到:

在此处输入图片说明

How to solve that? 怎么解决呢? Thanks in advance. 提前致谢。

I found the problem. 我发现了问题。 First time I show this window with function LoadUC with DataTable parameter but when I am changing the page I call LoadSearchGridView() function without to send again the DataTable (DataSource for GridView) and the DataSource alredy is null. 第一次显示带有带DataTable参数的LoadUC函数的窗口,但是当我更改页面时,我调用LoadSearchGridView()函数而没有再次发送DataTable(GridView的DataSource),并且DataSource alredy为null。

Now I'm sending always the DataTable for DataSource and pagination works perfect. 现在,我始终发送用于数据源的数据表,并且分页效果很好。

Thanks for all. 谢谢大家 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM