【问题标题】:How to use Gridview Paging in modal popup window ASP.NET Bootstrap 4.0如何在模式弹出窗口 ASP.NET Bootstrap 4.0 中使用 Gridview 分页
【发布时间】:2018-03-16 17:54:43
【问题描述】:

需要建议,为什么分页无法正常工作或事件触发但弹出页面未正确刷新。 我用 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();
}

当我更改页面时,我得到:

如何解决? 提前致谢。

【问题讨论】:

    标签: c# asp.net bootstrap-4


    【解决方案1】:

    我发现了问题。我第一次使用带有 DataTable 参数的函数 LoadUC 显示此窗口,但是当我更改页面时,我调用 LoadSearchGridView() 函数而不再次发送 DataTable(GridView 的数据源)并且 DataSource 已经为空。

    现在我总是为 DataSource 发送 DataTable,并且分页效果很好。

    谢谢大家。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多