Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to cast object of type '<TakeIterator>[System.Data.DataView]' to type 'System.Data.DataView'.?

Tags:

c#

asp.net

linq

i am using dataview and with it's skip and take methods, that will take 5 rows and skip some rows according to the page number and page size.

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

and next line in which i am facing error is:

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

At above line error occur is:

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

needs help. thanx.

like image 366
Mogli Avatar asked Jan 24 '26 15:01

Mogli


1 Answers

It works a little bit different, 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();

Not forget the "using System.Data;" and if you have time look for LINQ...

like image 160
Laszlo Boke Avatar answered Jan 26 '26 03:01

Laszlo Boke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!