?
Solved

query.Skip not working

Posted on 2011-09-09
4
Medium Priority
?
244 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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