How to draw an object of type '<TakeIterator> [System.Data.DataView]' to type 'System.Data.DataView'.?

I am using dataview and with it skip and take methods that will take 5 lines and skip some lines according to page number and page size.

//creating a dataview object and assigning table[0]
dv = new DataView(ds.Tables[0]);

      

and the following line where I am facing the error:

dv=(DataView)dv.Cast<System.Data.DataView>().Skip((pageNum-1)*pageSize).Take(5);

      

If the line is exceeded, an error occurs:

Unable to cast object of type '<TakeIterator>d__3a`1[System.Data.DataView]' to type 'System.Data.DataView'.

      

help is needed. Thanx.

+3


source to share


1 answer


It works a little differently, you can do the following:

        var dt = ds.Tables[0];
        dt = dt.AsEnumerable().Skip((pageNum - 1) * pageSize).Take(5).CopyToDataTable();

        var dv = new DataView(dt);
        GridView1.DataSource = dv;
        GridView1.DataBind();

      



Don't forget to use "System.Data"; and if you have time to look for LINQ ...

+4


source







All Articles