Repeater分页出现:"输入字符串的格式不正确"
using System;using System.Collections;
using
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace _021Repeater
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label lable1;
protected System.Web.UI.WebControls.Label lblCurPage;
protected System.Web.UI.WebControls.Button btnPre;
protected System.Web.UI.WebControls.Button btnNext;
protected System.Web.UI.WebControls.Repeater Repeater2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
this.bindtoRepeater();
this.lblCurPage.Text="1";
}
}
private void bindtoRepeater()
{
int curPage=Convert.ToInt16(this.lblCurPage.Text);//这里提示:"输入字符串的格式不正确"
SqlConnection con=DB.createCon();
con.Open();
SqlDataAdapter sda=new SqlDataAdapter("select * from employees",con);
DataSet ds=new DataSet();
sda.Fill(ds,"emp");
System.Web.UI.WebControls.PagedDataSource ps=new PagedDataSource();
ps.DataSource=ds.Tables["emp"].DefaultView;
ps.AllowPaging=true;
ps.PageSize=3;
ps.CurrentPageIndex=curPage-1;
this.btnPre.Enabled=true;
this.btnNext.Enabled=true;
if(curPage==1)
{
this.btnPre.Enabled=false;
}
if(curPage==ps.PageCount)
{
this.btnNext.Enabled=false;
}
this.Repeater2.DataSource=ps;
this.Repeater2.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnPre.Click += new System.EventHandler(this.btnPre_Click);
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnPre_Click(object sender, System.EventArgs e)
{
this.lblCurPage.Text=Convert.ToString(Convert.ToInt32(this.lblCurPage.Text)-1);
this.bindtoRepeater();
}
private void btnNext_Click(object sender, System.EventArgs e)
{
this.lblCurPage.Text=Convert.ToString(Convert.ToInt32(this.lblCurPage.Text)+1);
this.bindtoRepeater();
}
}
}