I'm programming on Asp.net and C#.
I have a Dataset which is populated by records from database. On my design page, I have two Datagrids.
How can I equally divide the records inside the Dataset so they can be bound to two separate datagrids?
you can use DataView on your dataset and then bind your 2 Datagrids on dataview here a sample http://www.dotnetperls.com/dataview
work for instance to set one dataview on rows.count/2 and the other too
This works for me,
var d=ds.Tables[0];// here ds is your dataset.
int count=d.Rows.Count;
var x=new DataTable();
for(int i=0;i<=count;i++)
{
var dr=d.Rows[i];
x.Rows.Add(dr.ItemArray);
d.Rows.RemoveAt(i);
}
var ret=new DataSet();
ret.Tables.Add(x);
ret.Tables.Add(d);
so now you have dataset that contain two equal datatable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.