protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
private void bind()
{
//用SQL的 like
string sql = "select * from w_bloglog where uid=" + Session["UID"] + " and logclass like '%" + this.DropDownList1.SelectedValue.ToString() + "%' order by LogTime desc";
Db g = new Db();//这里是调用我自定义的一个类 你老实写 Gridview绑定就是了
this.GridView1.DataSource = g.GetGrid(sql);
this.GridView1.DataKeyNames=new string[]{"logid"};
this.GridView1.DataBind();
if (this.GridView1.Rows.Count == 0)
{
Response.Write("<div align='center'>没有日志记录</center>");
this.t.Visible = false;
}
CurrPage.Text = "第" + Convert.ToInt32(GridView1.PageIndex + 1).ToString() + "页,共" + GridView1.PageCount + "页";
int curpage = Convert.ToInt32(GridView1.PageIndex + 1);
this.MoveFirst.Enabled = true;
this.MoveLast.Enabled = true;
this.MoveNext.Enabled = true;
this.MovePrev.Enabled = true;
if (curpage == 1)
{
this.MoveFirst.Enabled = false;//不显示第一页按钮
this.MovePrev.Enabled = false;//不显示上一页按钮
}
if (curpage == GridView1.PageCount)
{
this.MoveNext.Enabled = false;//不显示下一页
this.MoveLast.Enabled = false;//不显示最后一页
}
}
//自定义分页
protected void PagerChange(object sender, CommandEventArgs e)
{
switch (Convert.ToString(e.CommandArgument))
{
case "next":
// bind();
if (GridView1.PageIndex < GridView1.PageCount - 1)
GridView1.PageIndex = GridView1.PageIndex + 1;
bind();
break;
case "prev":
// bind();
if (GridView1.PageIndex > 0)
GridView1.PageIndex = GridView1.PageIndex - 1;
bind();
break;
case "last":
GridView1.PageIndex = GridView1.PageCount - 1;
bind();
break;
case "fir":
GridView1.PageIndex = 0;
bind();
break;
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.EditIndex = -1;
this.GridView1.PageIndex = e.NewPageIndex;//分页绑定
bind();
}