用户控件中的数据网格

发布于 2024-08-31 13:00:12 字数 370 浏览 3 评论 0原文

我在 UserControl 中有一个 DataGrid。不知怎的,分页不起作用,分页有正确的页面数量,但点击数字不起作用......它停留在第 1 页。这是我的网格:

<asp:DataGrid ID="DG_Grid" runat="server" AllowPaging="True" PageSize="10" EnableViewState="True"
            AllowSorting="False" DataKeyField="DUEDATE" OnItemDataBound="DG_Grid_ItemDataBound" OnItemCommand="DG_Grid_ItemCommand">

有人有想法吗?

I have a DataGrid in a USerControl. Somehow the paging doesnt work, the paging has the right amount of pages, but clicking the numbers does not work ... it stays on page 1. This is my Grid:

<asp:DataGrid ID="DG_Grid" runat="server" AllowPaging="True" PageSize="10" EnableViewState="True"
            AllowSorting="False" DataKeyField="DUEDATE" OnItemDataBound="DG_Grid_ItemDataBound" OnItemCommand="DG_Grid_ItemCommand">

Ideas anyone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迟月 2024-09-07 13:00:12

您处理过 PageIndexChanged 事件吗?有关详细信息,请参阅此处

Have you handled PageIndexChanged event? See here for more details.

深巷少女 2024-09-07 13:00:12

用户控件的数据网格是绑定在页面中还是用户控件本身中?我认为您将它们绑定在页面中,然后在页面中对它们进行排序。因此,您必须从 UserControl 引发 PageIndexChanged 事件并在页面中处理它。

这个例子是针对 GridView 的,但对于 DataGrid 来说是一样的。

在 UserControl 中定义您在页面中处理的事件:

    Public Event GridPageChanged(ByVal grid As GridView)

    Private Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged
        RaiseEvent GridPageChanged(Me.GridView1)
    End Sub

您现在可以在页面中捕获用户控件的 GridPageChanged 并进行排序。

Is the Usercontrols' Datagrid binded in the Page or in the Usercontrol itself? I think you bind them in the page and you dou sort them in the page. So you have to raise the PageIndexChanged Event from the UserControl and handle it in the page.

This exmaple is with GridView but for DataGrid its the same.

In the UserControl define an event that you handle in your Page:

    Public Event GridPageChanged(ByVal grid As GridView)

    Private Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged
        RaiseEvent GridPageChanged(Me.GridView1)
    End Sub

You can now catch the usercontrol's GridPageChanged in your Page and do the sorting.

沫雨熙 2024-09-07 13:00:12

像这样使用:

 private void FillGrid(int aPageNumber)
    {
       //Insert you code here


        DG_Grid.DataSource = _ds.Tables[0].DefaultView;
        DG_Grid.PageIndex = aPageNumber;
        DG_Grid.DataBind();
    }

的事件:

 protected void DG_Grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        FillGrid(e.NewPageIndex);
    }

在此调用之后,网格加载调用

 FillGrid(0);

Use like this:

 private void FillGrid(int aPageNumber)
    {
       //Insert you code here


        DG_Grid.DataSource = _ds.Tables[0].DefaultView;
        DG_Grid.PageIndex = aPageNumber;
        DG_Grid.DataBind();
    }

And after this call this event of grid

 protected void DG_Grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        FillGrid(e.NewPageIndex);
    }

On Load call:

 FillGrid(0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文