//Repeater分页控制显示方法
    public void contrlRepeater(int userId)
    {
        string connectionString = ConfigurationManager.ConnectionStrings["db_health"].ConnectionString;
        SqlConnection conn = new SqlConnection(connectionString);
        conn.Open();
        string sql = "select * from health_user_followup_content where user_id=" + userId + "";
        SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
        DataSet ds = new DataSet();
        sda.Fill(ds,"FollowContent");
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables["FollowContent"].DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 5;
        pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;
        rpUserList.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;
        }
        rpUserList.DataBind();
    }pds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;————刚点击进入页面时,为什么我这句会提示:”输入字符串的格式不正确”

解决方案 »

  1.   


    pds.CurrentPageIndex =(this.labPage.Text==null?1:("".Equals(this.labPage.Text)?1: Convert.ToInt32(this.labPage.Text))) - 1;有可能是null 或""无法正确转型
      

  2.   

    this.labPage.Text 首先需要判断是否有值而且是数字
      

  3.   


    this.labPage.Text = "1";
    我在开始加载页面时候写了这么一句
      

  4.   

    你这个方法是在 Load事件么?
    在页面加载的时候控制还未生成!
    this.labPage还未被实例化
    好好调试看看this.labPage是什么状态。
      

  5.   


    我是在page_load里面调用方法,写了如下两句
    如:contrlRepeater(userId);
        this.labPage.Text = "1";
    然后下面写了刚才发的方法加上按钮的事件
    如下:
     //Repeater分页控制显示方法
        public void contrlRepeater(int userId)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["db_health"].ConnectionString;
            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            string sql = "select * from health_user_followup_content where user_id=" + userId + "";
            SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
            DataSet ds = new DataSet();
            sda.Fill(ds,"FollowContent");
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables["FollowContent"].DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = 5;
            pds.CurrentPageIndex =Convert.ToInt32(labPage.Text) - 1;
            //pds.CurrentPageIndex = (this.labPage.Text == null ? 1 : ("".Equals(this.labPage.Text) ? 1 : Convert.ToInt32(this.labPage.Text))) - 1;
            rpUserList.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;
            }
            rpUserList.DataBind();
        }    protected void lbtnpritPage_Click(object sender, EventArgs e)
        {
            this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) - 1);
            this.contrlRepeater(userId);
        }    protected void lbtnFirstPage_Click(object sender, EventArgs e)
        {
            this.labPage.Text = "1";
            this.contrlRepeater(userId);
        }    protected void lbtnDownPage_Click(object sender, EventArgs e)
        {
            this.labPage.Text = this.LabCountPage.Text;
            this.contrlRepeater(userId);
        }    protected void lbtnNextPage_Click(object sender, EventArgs e)
        {
            this.labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text) + 1);
            this.contrlRepeater(userId);
        }
      

  6.   

    你没发现问题么?如:contrlRepeater(userId);
      this.labPage.Text = "1";

    this.labPage.Text = "1";
    contrlRepeater(userId);
    //this.labPage.Text = "1"; 确实意义已经不大了。
    pds.CurrentPageIndex =(this.labPage.Text==null?1:("".Equals(this.labPage.Text)?1: Convert.ToInt32(this.labPage.Text))) - 1;
    你有调试下这句话么.
    编程要有严谨性.要不你以后编写代码会很吃力的。
      
      

  7.   

    调试一下 看这个的转换结果是什么 Convert.ToInt32(labPage.Text) - 1;
     
      

  8.   

    1.如果去掉this.labPage.Text = "1";
    pds.CurrentPageIndex =(this.labPage.Text==null?1:("".Equals(this.labPage.Text)?1: Convert.ToInt32(this.labPage.Text))) - 1;会报出刚才的错误
    2.如果加上this.labPage.Text = "1";同事放在调用那个方法的前面
    你给的那句就不会有错误,currentpageindex为0
      

  9.   


    如果去掉this.labPage.Text = "1";会报错
    如果加上this.labPage.Text = "1";就直接运行通过,currentpageindex为0
      

  10.   

    看你的代码思路不是很清晰。
    //直接传页码  在第一次加载时 this.labPage.Text = "1";
    public void contrlRepeater(int userId,int page)pds.CurrentPageIndex =page-1;
    //有想法就自己写个分页控件, 封装所有分页属性。 在项目才能得共用复用。