帮我看看Datalist怎么不能翻页
protected string s_title= " ";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
s_title=Request.QueryString[ "title "];
if(s_title!= " ")
{
txtSearch.Text=s_title;
//SearchMore1.Title=s_title;
}
this.bind();
}
}
private void ImageButton2_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect( "/web/Search/search.aspx?title= "+this.txtSearch.Text.Trim());
}
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect( "/web/Search/Search_Gj.aspx ");
}
public void bind()
{ string sql= "Server=(local);database=chtcms;user id=sa;pwd=sa ";
int curpage= Convert.ToInt32(this.Label2.Text);
PagedDataSource ps = new PagedDataSource();
SqlConnection sqlcon= new SqlConnection(sql);
sqlcon.Open();
string sqlstr = "select * from info where title like '% "+ txtSearch.Text + "% ' ";
SqlDataAdapter da = new SqlDataAdapter(sqlstr,sqlcon);
DataSet ds =new DataSet();
da.Fill(ds, "info ");
ps.DataSource= ds.Tables[ "info "].DefaultView;
ps.AllowPaging=true;
ps.PageSize=10;
ps.CurrentPageIndex = curpage-1;
this.lnkbtone.Enabled=true;
this.Linkbup.Enabled=true;
this.LinkBnext.Enabled=true;
this.LinkBack.Enabled=true;
if(curpage == 1)
{
this.lnkbtone.Enabled = false;
this.Linkbup.Enabled=false;
}
if(curpage == ps.PageCount)
{
this.LinkBnext.Enabled=false;
this.LinkBnext.Enabled=false;
}
this.Label4.Text=Convert.ToString(ps.PageCount);
this.DataList1.DataSource= ps;
this.DataList1.DataKeyField= "id ";
this.DataList1.DataBind();
sqlcon.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Linkbup.Click += new System.EventHandler(this.Linkbup_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void lnkbtone_Click(object sender, System.EventArgs e)
{
this.Label2.Text= "1 ";
this.bind();
}
private void Linkbup_Click(object sender, System.EventArgs e)
{
this.Label2.Text=Convert.ToString(Convert.ToInt32(this.Labe