public void contrlRepeater()
{
string cxtj, txtBox, sql = "";
txtBox = this.TextBox1.Text.Trim();
cxtj = this.cxtj.SelectedValue;
if (cxtj == "log_Title")
{
sql = "select id,title,author,timedate from news where title like '%" + txtBox + "%' order by id desc";
}
if (cxtj == "log_Content")
{ sql = "select id,title,author,timedate from news where content like '%" + txtBox + "%' order by id desc"; }
if (cxtj == "请选择")
{ sql = "select id,title,author,timedate from news order by id desc"; }
string StrConn = @"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=";
StrConn += Server.MapPath(".\\App_Data\\news.mdb");
OleDbConnection conn = new OleDbConnection(StrConn);
conn.Open();
OleDbDataAdapter Comm = new OleDbDataAdapter(sql, conn); DataSet ds = new DataSet(); //DataSet 初试化
Comm.Fill(ds, "Book");
//使用PagedDataSource来实现分页
this.GridView1.AllowPaging = false;
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["Book"].DefaultView[0];
pds.AllowPaging = true;
pds.PageSize = 10;
pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
this.GridView1.DataSource = pds;
LabCountPage.Text = pds.PageCount.ToString();
labPage.Text = (pds.CurrentPageIndex + 1).ToString();
this.lbtnpritPage.Enabled = true;
this.lbtnFirstPage.Enabled = true;
this.lbtnNextPage.Enabled = true;
this.lbtnDownPage.Enabled = true;
if (pds.CurrentPageIndex < 1)
{
this.lbtnpritPage.Enabled = false;
this.lbtnFirstPage.Enabled = false;
}
if (pds.CurrentPageIndex == pds.PageCount - 1)
{
this.lbtnNextPage.Enabled = false;
this.lbtnDownPage.Enabled = false;
}
GridView1.DataBind();//此处出现异常:索引 10 不是为负数,就是大于行数。点上下页控件出现
conn.Close();
}
{
string cxtj, txtBox, sql = "";
txtBox = this.TextBox1.Text.Trim();
cxtj = this.cxtj.SelectedValue;
if (cxtj == "log_Title")
{
sql = "select id,title,author,timedate from news where title like '%" + txtBox + "%' order by id desc";
}
if (cxtj == "log_Content")
{ sql = "select id,title,author,timedate from news where content like '%" + txtBox + "%' order by id desc"; }
if (cxtj == "请选择")
{ sql = "select id,title,author,timedate from news order by id desc"; }
string StrConn = @"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=";
StrConn += Server.MapPath(".\\App_Data\\news.mdb");
OleDbConnection conn = new OleDbConnection(StrConn);
conn.Open();
OleDbDataAdapter Comm = new OleDbDataAdapter(sql, conn); DataSet ds = new DataSet(); //DataSet 初试化
Comm.Fill(ds, "Book");
//使用PagedDataSource来实现分页
this.GridView1.AllowPaging = false;
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["Book"].DefaultView[0];
pds.AllowPaging = true;
pds.PageSize = 10;
pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
this.GridView1.DataSource = pds;
LabCountPage.Text = pds.PageCount.ToString();
labPage.Text = (pds.CurrentPageIndex + 1).ToString();
this.lbtnpritPage.Enabled = true;
this.lbtnFirstPage.Enabled = true;
this.lbtnNextPage.Enabled = true;
this.lbtnDownPage.Enabled = true;
if (pds.CurrentPageIndex < 1)
{
this.lbtnpritPage.Enabled = false;
this.lbtnFirstPage.Enabled = false;
}
if (pds.CurrentPageIndex == pds.PageCount - 1)
{
this.lbtnNextPage.Enabled = false;
this.lbtnDownPage.Enabled = false;
}
GridView1.DataBind();//此处出现异常:索引 10 不是为负数,就是大于行数。点上下页控件出现
conn.Close();
}
if(ds.Tables.Rows.Count<=10)
{
pds.AllowPaging = false;
}