Solved

query.Skip not working

Posted on 2011-09-09
4
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 18

Expert Comment

by:dj_alik
ID: 36515357
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
ID: 36527187
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
ID: 36553565
using new filter datatable instead.  everything works now.
0
 
LVL 1

Author Comment

by:melinalt
ID: 36550410
solved
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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