簡體   English   中英

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

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

需要建議,為什么分頁無法正常工作或事件啟動但彈出頁面未正確刷新。 我制作了一個具有Bootstrap模式內容和GridView的用戶控件。

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>

使用此腳本,我顯示彈出窗口:

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();
    }
}

因此,我更改頁面:

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

當我更改頁面時,我得到:

在此處輸入圖片說明

怎么解決呢? 提前致謝。

我發現了問題。 第一次顯示帶有帶DataTable參數的LoadUC函數的窗口,但是當我更改頁面時,我調用LoadSearchGridView()函數而沒有再次發送DataTable(GridView的DataSource),並且DataSource alredy為null。

現在,我始終發送用於數據源的數據表,並且分頁效果很好。

謝謝大家 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM