《Gridview实现分页小列子》由会员分享,可在线阅读,更多相关《Gridview实现分页小列子(6页珍藏版)》请在金锄头文库上搜索。
1、using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace new_project public partial class news_f : Form dataBase db = new dataBase(); public news_f() Initial
2、izeComponent(); private void Form1_Load(object sender, EventArgs e) showPage(); /OleDbDataAdapter da=new OleDbDataAdapter(“select DataSet ds = db.getData(); /myDGV.DataSource = ds.Tables0; /MessageBox.Show(ds.Tables0.Rows.Count.ToString(); /myDGV.pag myCombo.DataSource = ds.Tables0; myCombo.DisplayM
3、ember = “新闻标题“; myCombo.ValueMember = “新闻 ID“; /for (int i = 0; i 1) db.page = 1; showPage(); private void prevPage_Click(object sender, EventArgs e) if (db.page 1) db.page-; showPage(); else MessageBox.Show(“This is the first Page“); private void nextPage_Click(object sender, EventArgs e) if (db.pa
4、ge db.pageCount) db.page = db.pageCount; String sql = “select newsId as新闻 ID, title as 新闻标题, content as 新闻内容 from news order by newsId desc“; OleDbDataAdapter DA = new OleDbDataAdapter(sql, db.conn); DataSet DS = new DataSet(); DA.Fill(DS, (db.page - 1) * db.pageSize + 1, db.pageSize, “news“); myDGV
5、.DataSource = DS.Tables0; db.conn.Close(); pageInfo.Text = “Total:“ + db.recordCount + “ Page:“ + db.page + “/“ + db.pageCount; if (db.page = 1) firstPage.Enabled = false; prevPage.Enabled = false; else firstPage.Enabled = true; prevPage.Enabled = true; if (db.page = db.pageCount) nextPage.Enabled = false; lastPage.Enabled = false; else nextPage.Enabled = true; lastPage.Enabled = true;