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

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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Albert D. Kallal