.Net Framework 4 中是否提供自定义分页,如果是,我们如何实现?

发布于 2025-01-13 01:58:50 字数 113 浏览 3 评论 0原文

.Net Framework 4 中是否提供自定义分页,如果是,我们如何实现?

目前我正在通过使用 GridView.VirtualItemCount 来实现此功能,但这在 .NET 4 中不可用。

Was custom pagination available in .Net Framework 4, If yes how we can implement?

Currently I am implementing this by using GridView.VirtualItemCount however this is not avaible in .NET 4.

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

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

发布评论

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

评论(1

┼── 2025-01-20 01:58:50

嗯,看来 VirtualItemCount 在 .net 4.0 中不可用。

但是,GridViews 在 .net 4.0 中仍然支持分页。

因此,如果我有一个 gv,并像这样打开分页:

      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            CssClass="table table-hover" Width="50%"
            DataKeyNames="ID" AllowPaging="True">
            <Columns>
                <asp:BoundField DataField="FirstName" HeaderText="FirstName"  />
                <asp:BoundField DataField="LastName" HeaderText="LastName" />
                <asp:TemplateField HeaderText="Hotel Name" />
                <asp:BoundField DataField="Description" HeaderText="Description" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="txtHotel" runat="server"
                            Text='<%# Eval("HotelName") %>' >
                        </asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                    <asp:LinkButton ID="cmdDelete" runat="server" CssClass="btn btn-default"
                     OnClick="cmdDelete_Click" 
                     OnClientClick="return mydelprompt(this)"   >
                   <span aria-hidden="true" class="glyphicon glyphicon-trash"></span>
                   Delete                            
                   </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

并且要加载的代码 - (不要使用数据读取器加载 - 它们不起作用 - 你需要一个“可交互”的数据源。

所以,要加载的代码网格可以是这样的:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
        LoadGrid()
    End If

End Sub

Sub LoadGrid()

    Using conn As New SqlConnection(My.Settings.TEST4)
        Dim strSQL As String =
            "SELECT * from tblHotels WHERE Description is not null 
             Order by HotelName"

        Using cmdSQL As New SqlCommand(strSQL, conn)
            conn.Open()
            Dim rst As New DataTable
            rst.Load(cmdSQL.ExecuteReader)
            GridView1.DataSource = rst
            GridView1.DataBind()
        End Using
    End Using

End Sub

它输出网格 - 使用工作寻呼机:

在此处输入图像描述

因此,似乎没有 virtualItemCount 可用,但您仍然可以使用 .net 4.0 中的 gv 打开数据分页。

Hum, it would seem that VirtualItemCount is not available in .net 4.0.

However, GridViews still supported paging in .net 4.0.

So, if I have a gv, and turn on paging like this:

      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            CssClass="table table-hover" Width="50%"
            DataKeyNames="ID" AllowPaging="True">
            <Columns>
                <asp:BoundField DataField="FirstName" HeaderText="FirstName"  />
                <asp:BoundField DataField="LastName" HeaderText="LastName" />
                <asp:TemplateField HeaderText="Hotel Name" />
                <asp:BoundField DataField="Description" HeaderText="Description" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="txtHotel" runat="server"
                            Text='<%# Eval("HotelName") %>' >
                        </asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                    <asp:LinkButton ID="cmdDelete" runat="server" CssClass="btn btn-default"
                     OnClick="cmdDelete_Click" 
                     OnClientClick="return mydelprompt(this)"   >
                   <span aria-hidden="true" class="glyphicon glyphicon-trash"></span>
                   Delete                            
                   </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

And code to load - (don't load with a data reader - they don't work - you need a "interable" data source.

So, code to load the grid can be this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
        LoadGrid()
    End If

End Sub

Sub LoadGrid()

    Using conn As New SqlConnection(My.Settings.TEST4)
        Dim strSQL As String =
            "SELECT * from tblHotels WHERE Description is not null 
             Order by HotelName"

        Using cmdSQL As New SqlCommand(strSQL, conn)
            conn.Open()
            Dim rst As New DataTable
            rst.Load(cmdSQL.ExecuteReader)
            GridView1.DataSource = rst
            GridView1.DataBind()
        End Using
    End Using

End Sub

And it outputs the grid - with a working pager:

enter image description here

So, no virtualItemCount seems to be available, but you can still turn on data paging with the gv in .net 4.0.

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