//这里是在定义分页的方法
public void PartitionPage(int count,int ts, DataGridView dataGridView1, ComboBox comboBox2, SqlDataAdapter srd, DataSet dset)
{
int page;
int index;
int counts = ts;
if (count % counts == 0)
{
page = count / counts;
}
else
{
page = (count - (count % counts)) / counts + 1;
}
for (int i = 1; i <= page; i++)
{
comboBox2.Items.Add(i);
}
if (count < counts)
{
dset.Clear();
srd.Fill(dset, 0, count, "one0");
dataGridView1.DataSource = dset.Tables[1];
}
else
{
if (count == counts)
{
dset.Clear();
srd.Fill(dset, 0, counts, "one0");
dataGridView1.DataSource = dset.Tables[1];
}
else
{
index = Int32.Parse(comboBox2.Text.ToString()) * counts - (Int32.Parse(comboBox2.Text.ToString()) - (Int32.Parse(comboBox2.Text.ToString()) - 1)) * counts;
dset.Clear();
srd.Fill(dset, index, counts, "one0");
dataGridView1.DataSource = dset.Tables[1];
}
}
}
取出数据时:
CommonClass cs = new CommonClass();//分页方法所放的类实例化
dst = new DataSet();
sad = cs.OutvvData(sql_avg);//取出数据
sad.Fill(dst, "one");
int counts=dst.Tables[0].Rows.Count;//所有数据的调试
cs.fpage(counts,15, this.dataGridView1, this.comboBox2, sad, dst); //15为每页的显示的数据的条数,comboBox2为翻页的下拉框
//这里是在定义刷新时分页的方法
public void vfpage(int count,int ts, DataGridView dataGridView1, ComboBox comboBox2, SqlDataAdapter srd, DataSet dset)
{
int page;
int index;
int counts = ts;
index = Int32.Parse(comboBox2.Text.ToString()) * counts - (Int32.Parse(comboBox2.Text.ToString()) - (Int32.Parse(comboBox2.Text.ToString()) - 1)) * counts;
if (count % counts == 0)
{
page = count / counts;
}
else
{
page = (count - (count % counts)) / counts + 1;
}
if (count < counts)
{
dset.Clear();
srd.Fill(dset, 0, count, "one0");
dataGridView1.DataSource = dset.Tables[1];
}
else
{
if (count == counts)
{
dset.Clear();
srd.Fill(dset, 0, counts, "one0");
dataGridView1.DataSource = dset.Tables[1];
}
else
{
dset.Clear();
srd.Fill(dset, index, counts, "one0");
dataGridView1.DataSource = dset.Tables[1];
}
}
}