Solved

query.Skip not working

Posted on 2011-09-09
4
239 Views
Last Modified: 2012-05-12
I have the code below to page a gridview but the query.skip doesn't work.

query.take works but qery.skip doesn't work

It always returns the first 5 rows of the datatable

Thanks,




Gridview

<asp:GridView Width="100%" ID="gvwData" CssClass="datatable" PageSize="5" runat="server"
            PagerSettings-Visible="true" >
</asp:GridView>


Code behind

Imports System.Linq.Dynamic

    Sub bindGrid()
        'bind grid data
        With Me.gvwData
            .Width = WebControls.Unit.Percentage(100)
            .EnableViewState = False
            .AutoGenerateColumns = False
            .DataSource = Me.GetFilteredData()
            .DataBind()
        End With
    End Sub

    Private Function GetFilteredData() As DataTable
        Dim dtFilterData As New DataTable
        'dynamic query against datatable 
        'select everything from currentdataset
        Dim query = From dv In Me.CurrentDataTable Select dv
        If Me.PageSize = -1 Then
            dtFilterData = query.CopyToDataTable
        Else
            'Skip the first (Me.CurrentPageIndex * Me.PageSize) records and take the next (pagezise)
            ' dtFilterData = query.Take(Me.PageSize).CopyToDataTable
            dtFilterData = query.Skip(Me.CurrentPageIndex * Me.PageSize).Take(Me.PageSize).CopyToDataTable
        End If
        Return dtFilterData
    End Function

Open in new window

0
Comment
Question by:melinalt
  • 3
4 Comments
 
LVL 18

Expert Comment

by:dj_alik
Comment Utility
did you have primary in datatable?

and
Me.CurrentPageIndex  was changed?

and did you debug your code and watch dtFilterData?

0
 
LVL 1

Accepted Solution

by:
melinalt earned 0 total points
Comment Utility
Never mind.. it was me all the time.

In my itemdatabound subroutine I kept using  Me.CurrentDataTable, which was the original datatable,  instead of dtFilterData.

Of course I was always displaying the same rows.. duh...

Thanks any way.

0
 
LVL 1

Author Closing Comment

by:melinalt
Comment Utility
using new filter datatable instead.  everything works now.
0
 
LVL 1

Author Comment

by:melinalt
Comment Utility
solved
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now