简体   繁体   中英

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.

ASP Page (Control):

<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.

Now I'm sending always the DataTable for DataSource and pagination works perfect.

Thanks for all. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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